feat: ask for password before previewing protected files (#991)
This commit is contained in:
@@ -15,6 +15,7 @@ import { StreamingFileReader } from '@standardnotes/filepicker'
|
|||||||
import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction'
|
import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction'
|
||||||
import { AttachedFilesPopover, PopoverTabs } from './AttachedFilesPopover'
|
import { AttachedFilesPopover, PopoverTabs } from './AttachedFilesPopover'
|
||||||
import { usePremiumModal } from '@/Hooks/usePremiumModal'
|
import { usePremiumModal } from '@/Hooks/usePremiumModal'
|
||||||
|
import { useFilePreviewModal } from '../Files/FilePreviewModalProvider'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
@@ -40,6 +41,8 @@ const removeDragOverlay = () => {
|
|||||||
export const AttachedFilesButton: FunctionComponent<Props> = observer(
|
export const AttachedFilesButton: FunctionComponent<Props> = observer(
|
||||||
({ application, appState, onClickPreprocessing }) => {
|
({ application, appState, onClickPreprocessing }) => {
|
||||||
const premiumModal = usePremiumModal()
|
const premiumModal = usePremiumModal()
|
||||||
|
const filePreviewModal = useFilePreviewModal()
|
||||||
|
|
||||||
const note = Object.values(appState.notes.selectedNotes)[0]
|
const note = Object.values(appState.notes.selectedNotes)[0]
|
||||||
|
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
@@ -205,6 +208,9 @@ export const AttachedFilesButton: FunctionComponent<Props> = observer(
|
|||||||
case PopoverFileItemActionType.RenameFile:
|
case PopoverFileItemActionType.RenameFile:
|
||||||
await renameFile(file, action.payload.name)
|
await renameFile(file, action.payload.name)
|
||||||
break
|
break
|
||||||
|
case PopoverFileItemActionType.PreviewFile:
|
||||||
|
filePreviewModal.activate(file)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
application.sync.sync().catch(console.error)
|
application.sync.sync().catch(console.error)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { useEffect, useRef, useState } from 'preact/hooks'
|
|||||||
import { Icon, ICONS } from '@/Components/Icon'
|
import { Icon, ICONS } from '@/Components/Icon'
|
||||||
import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction'
|
import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction'
|
||||||
import { PopoverFileSubmenu } from './PopoverFileSubmenu'
|
import { PopoverFileSubmenu } from './PopoverFileSubmenu'
|
||||||
import { useFilePreviewModal } from '@/Components/Files/FilePreviewModalProvider'
|
|
||||||
|
|
||||||
export const getFileIconComponent = (iconType: string, className: string) => {
|
export const getFileIconComponent = (iconType: string, className: string) => {
|
||||||
const IconComponent = ICONS[iconType as keyof typeof ICONS]
|
const IconComponent = ICONS[iconType as keyof typeof ICONS]
|
||||||
@@ -30,8 +29,6 @@ export const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
|
|||||||
getIconType,
|
getIconType,
|
||||||
closeOnBlur,
|
closeOnBlur,
|
||||||
}) => {
|
}) => {
|
||||||
const filePreviewModal = useFilePreviewModal()
|
|
||||||
|
|
||||||
const [fileName, setFileName] = useState(file.name)
|
const [fileName, setFileName] = useState(file.name)
|
||||||
const [isRenamingFile, setIsRenamingFile] = useState(false)
|
const [isRenamingFile, setIsRenamingFile] = useState(false)
|
||||||
const itemRef = useRef<HTMLDivElement>(null)
|
const itemRef = useRef<HTMLDivElement>(null)
|
||||||
@@ -68,8 +65,11 @@ export const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
|
|||||||
renameFile(file, fileName).catch(console.error)
|
renameFile(file, fileName).catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const clickHandler = () => {
|
const clickPreviewHandler = () => {
|
||||||
filePreviewModal.activate(file)
|
handleFileAction({
|
||||||
|
type: PopoverFileItemActionType.PreviewFile,
|
||||||
|
payload: file,
|
||||||
|
}).catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -78,7 +78,7 @@ export const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
|
|||||||
className="flex items-center justify-between p-3 focus:shadow-none"
|
className="flex items-center justify-between p-3 focus:shadow-none"
|
||||||
tabIndex={FOCUSABLE_BUT_NOT_TABBABLE}
|
tabIndex={FOCUSABLE_BUT_NOT_TABBABLE}
|
||||||
>
|
>
|
||||||
<div onClick={clickHandler} className="flex items-center cursor-pointer">
|
<div onClick={clickPreviewHandler} className="flex items-center cursor-pointer">
|
||||||
{getFileIconComponent(getIconType(file.mimeType), 'w-8 h-8 flex-shrink-0')}
|
{getFileIconComponent(getIconType(file.mimeType), 'w-8 h-8 flex-shrink-0')}
|
||||||
<div className="flex flex-col mx-4">
|
<div className="flex flex-col mx-4">
|
||||||
{isRenamingFile ? (
|
{isRenamingFile ? (
|
||||||
@@ -113,6 +113,7 @@ export const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
|
|||||||
handleFileAction={handleFileAction}
|
handleFileAction={handleFileAction}
|
||||||
setIsRenamingFile={setIsRenamingFile}
|
setIsRenamingFile={setIsRenamingFile}
|
||||||
closeOnBlur={closeOnBlur}
|
closeOnBlur={closeOnBlur}
|
||||||
|
previewHandler={clickPreviewHandler}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export enum PopoverFileItemActionType {
|
|||||||
DownloadFile,
|
DownloadFile,
|
||||||
RenameFile,
|
RenameFile,
|
||||||
ToggleFileProtection,
|
ToggleFileProtection,
|
||||||
|
PreviewFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PopoverFileItemAction =
|
export type PopoverFileItemAction =
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import { StateUpdater, useCallback, useEffect, useRef, useState } from 'preact/h
|
|||||||
import { Icon } from '@/Components/Icon'
|
import { Icon } from '@/Components/Icon'
|
||||||
import { Switch } from '@/Components/Switch'
|
import { Switch } from '@/Components/Switch'
|
||||||
import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur'
|
import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur'
|
||||||
import { useFilePreviewModal } from '@/Components/Files/FilePreviewModalProvider'
|
|
||||||
import { PopoverFileItemProps } from './PopoverFileItem'
|
import { PopoverFileItemProps } from './PopoverFileItem'
|
||||||
import { PopoverFileItemActionType } from './PopoverFileItemAction'
|
import { PopoverFileItemActionType } from './PopoverFileItemAction'
|
||||||
|
|
||||||
type Props = Omit<PopoverFileItemProps, 'renameFile' | 'getIconType'> & {
|
type Props = Omit<PopoverFileItemProps, 'renameFile' | 'getIconType'> & {
|
||||||
setIsRenamingFile: StateUpdater<boolean>
|
setIsRenamingFile: StateUpdater<boolean>
|
||||||
|
previewHandler: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PopoverFileSubmenu: FunctionComponent<Props> = ({
|
export const PopoverFileSubmenu: FunctionComponent<Props> = ({
|
||||||
@@ -19,9 +19,8 @@ export const PopoverFileSubmenu: FunctionComponent<Props> = ({
|
|||||||
isAttachedToNote,
|
isAttachedToNote,
|
||||||
handleFileAction,
|
handleFileAction,
|
||||||
setIsRenamingFile,
|
setIsRenamingFile,
|
||||||
|
previewHandler,
|
||||||
}) => {
|
}) => {
|
||||||
const filePreviewModal = useFilePreviewModal()
|
|
||||||
|
|
||||||
const menuContainerRef = useRef<HTMLDivElement>(null)
|
const menuContainerRef = useRef<HTMLDivElement>(null)
|
||||||
const menuButtonRef = useRef<HTMLButtonElement>(null)
|
const menuButtonRef = useRef<HTMLButtonElement>(null)
|
||||||
const menuRef = useRef<HTMLDivElement>(null)
|
const menuRef = useRef<HTMLDivElement>(null)
|
||||||
@@ -90,7 +89,7 @@ export const PopoverFileSubmenu: FunctionComponent<Props> = ({
|
|||||||
onBlur={closeOnBlur}
|
onBlur={closeOnBlur}
|
||||||
className="sn-dropdown-item focus:bg-info-backdrop"
|
className="sn-dropdown-item focus:bg-info-backdrop"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
filePreviewModal.activate(file)
|
previewHandler()
|
||||||
closeMenu()
|
closeMenu()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user