diff --git a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx index 2f7b79da40d..9575d4c840e 100644 --- a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx +++ b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx @@ -15,6 +15,7 @@ import { StreamingFileReader } from '@standardnotes/filepicker' import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction' import { AttachedFilesPopover, PopoverTabs } from './AttachedFilesPopover' import { usePremiumModal } from '@/Hooks/usePremiumModal' +import { useFilePreviewModal } from '../Files/FilePreviewModalProvider' type Props = { application: WebApplication @@ -40,6 +41,8 @@ const removeDragOverlay = () => { export const AttachedFilesButton: FunctionComponent = observer( ({ application, appState, onClickPreprocessing }) => { const premiumModal = usePremiumModal() + const filePreviewModal = useFilePreviewModal() + const note = Object.values(appState.notes.selectedNotes)[0] const [open, setOpen] = useState(false) @@ -205,6 +208,9 @@ export const AttachedFilesButton: FunctionComponent = observer( case PopoverFileItemActionType.RenameFile: await renameFile(file, action.payload.name) break + case PopoverFileItemActionType.PreviewFile: + filePreviewModal.activate(file) + break } application.sync.sync().catch(console.error) diff --git a/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileItem.tsx b/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileItem.tsx index 010d2527bde..f26812a6f29 100644 --- a/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileItem.tsx +++ b/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileItem.tsx @@ -7,7 +7,6 @@ import { useEffect, useRef, useState } from 'preact/hooks' import { Icon, ICONS } from '@/Components/Icon' import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction' import { PopoverFileSubmenu } from './PopoverFileSubmenu' -import { useFilePreviewModal } from '@/Components/Files/FilePreviewModalProvider' export const getFileIconComponent = (iconType: string, className: string) => { const IconComponent = ICONS[iconType as keyof typeof ICONS] @@ -30,8 +29,6 @@ export const PopoverFileItem: FunctionComponent = ({ getIconType, closeOnBlur, }) => { - const filePreviewModal = useFilePreviewModal() - const [fileName, setFileName] = useState(file.name) const [isRenamingFile, setIsRenamingFile] = useState(false) const itemRef = useRef(null) @@ -68,8 +65,11 @@ export const PopoverFileItem: FunctionComponent = ({ renameFile(file, fileName).catch(console.error) } - const clickHandler = () => { - filePreviewModal.activate(file) + const clickPreviewHandler = () => { + handleFileAction({ + type: PopoverFileItemActionType.PreviewFile, + payload: file, + }).catch(console.error) } return ( @@ -78,7 +78,7 @@ export const PopoverFileItem: FunctionComponent = ({ className="flex items-center justify-between p-3 focus:shadow-none" tabIndex={FOCUSABLE_BUT_NOT_TABBABLE} > -
+
{getFileIconComponent(getIconType(file.mimeType), 'w-8 h-8 flex-shrink-0')}
{isRenamingFile ? ( @@ -113,6 +113,7 @@ export const PopoverFileItem: FunctionComponent = ({ handleFileAction={handleFileAction} setIsRenamingFile={setIsRenamingFile} closeOnBlur={closeOnBlur} + previewHandler={clickPreviewHandler} />
) diff --git a/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileItemAction.tsx b/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileItemAction.tsx index b774c6b90da..6f6cdf9948f 100644 --- a/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileItemAction.tsx +++ b/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileItemAction.tsx @@ -7,6 +7,7 @@ export enum PopoverFileItemActionType { DownloadFile, RenameFile, ToggleFileProtection, + PreviewFile, } export type PopoverFileItemAction = diff --git a/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileSubmenu.tsx b/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileSubmenu.tsx index fe5a94e5fde..d1d77a05469 100644 --- a/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileSubmenu.tsx +++ b/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileSubmenu.tsx @@ -6,12 +6,12 @@ import { StateUpdater, useCallback, useEffect, useRef, useState } from 'preact/h import { Icon } from '@/Components/Icon' import { Switch } from '@/Components/Switch' import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur' -import { useFilePreviewModal } from '@/Components/Files/FilePreviewModalProvider' import { PopoverFileItemProps } from './PopoverFileItem' import { PopoverFileItemActionType } from './PopoverFileItemAction' type Props = Omit & { setIsRenamingFile: StateUpdater + previewHandler: () => void } export const PopoverFileSubmenu: FunctionComponent = ({ @@ -19,9 +19,8 @@ export const PopoverFileSubmenu: FunctionComponent = ({ isAttachedToNote, handleFileAction, setIsRenamingFile, + previewHandler, }) => { - const filePreviewModal = useFilePreviewModal() - const menuContainerRef = useRef(null) const menuButtonRef = useRef(null) const menuRef = useRef(null) @@ -90,7 +89,7 @@ export const PopoverFileSubmenu: FunctionComponent = ({ onBlur={closeOnBlur} className="sn-dropdown-item focus:bg-info-backdrop" onClick={() => { - filePreviewModal.activate(file) + previewHandler() closeMenu() }} >