diff --git a/packages/web/src/javascripts/Components/FilePreview/FilePreviewModal.tsx b/packages/web/src/javascripts/Components/FilePreview/FilePreviewModal.tsx index bfdc183ab..6f605597c 100644 --- a/packages/web/src/javascripts/Components/FilePreview/FilePreviewModal.tsx +++ b/packages/web/src/javascripts/Components/FilePreview/FilePreviewModal.tsx @@ -14,6 +14,9 @@ import FileMenuOptions from '../FileContextMenu/FileMenuOptions' import Menu from '../Menu/Menu' import Popover from '../Popover/Popover' import LinkedItemBubblesContainer from '../LinkedItems/LinkedItemBubblesContainer' +import StyledTooltip from '../StyledTooltip/StyledTooltip' +import DecoratedInput from '../Input/DecoratedInput' +import { mergeRefs } from '@/Hooks/mergeRefs' type Props = { application: WebApplication @@ -27,6 +30,8 @@ const FilePreviewModal: FunctionComponent = observer(({ application, view return null } + const [isRenaming, setIsRenaming] = useState(false) + const renameInputRef = useRef(null) const [showLinkedBubblesContainer, setShowLinkedBubblesContainer] = useState(false) const [showOptionsMenu, setShowOptionsMenu] = useState(false) const [showFileInfoPanel, setShowFileInfoPanel] = useState(false) @@ -75,6 +80,25 @@ const FilePreviewModal: FunctionComponent = observer(({ application, view [currentFile.mimeType], ) + const focusInputOnMount = useCallback((input: HTMLInputElement | null) => { + if (input) { + input.focus() + } + }, []) + + const handleRename = useCallback(async () => { + if (renameInputRef.current) { + const newName = renameInputRef.current.value + if (newName && newName !== currentFile.name) { + await application.items.renameFile(currentFile, newName) + setIsRenaming(false) + setCurrentFile(application.items.findSureItem(currentFile.uuid)) + return + } + setIsRenaming(false) + } + }, [application.items, currentFile, setCurrentFile]) + return ( = observer(({ application, view tabIndex={FOCUSABLE_BUT_NOT_TABBABLE} onKeyDown={keyDownHandler} > -
+
{IconComponent}
- {currentFile.name} + {isRenaming ? ( + { + if (event.key === KeyboardKey.Enter) { + void handleRename() + } + }} + right={[ + , + ]} + ref={mergeRefs([renameInputRef, focusInputOnMount])} + /> + ) : ( + {currentFile.name} + )}
- - + + + + + + + + + = observer(({ application, view /> - + + +