From 34e54b4944e3352a9baa394146bcea37b871cf90 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Mon, 5 Aug 2019 21:02:36 -0700 Subject: [PATCH] Slightly better logic for dropdown menus --- .../server/files/FileDropdownMenu.tsx | 26 ++++++++--- .../server/files/RenameFileModal.tsx | 45 ++++++++++++------- 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/resources/scripts/components/server/files/FileDropdownMenu.tsx b/resources/scripts/components/server/files/FileDropdownMenu.tsx index a39751625..6fc8a4b77 100644 --- a/resources/scripts/components/server/files/FileDropdownMenu.tsx +++ b/resources/scripts/components/server/files/FileDropdownMenu.tsx @@ -9,7 +9,6 @@ import { faCopy } from '@fortawesome/free-solid-svg-icons/faCopy'; import { faLevelUpAlt } from '@fortawesome/free-solid-svg-icons/faLevelUpAlt'; import RenameFileModal from '@/components/server/files/RenameFileModal'; import { ServerContext } from '@/state/server'; -import CopyFileModal from '@/components/server/files/CopyFileModal'; import { join } from 'path'; import deleteFile from '@/api/server/files/deleteFile'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; @@ -20,6 +19,7 @@ type ModalType = 'rename' | 'move'; export default ({ uuid }: { uuid: string }) => { const menu = createRef(); + const menuButton = createRef(); const [ visible, setVisible ] = useState(false); const [ showSpinner, setShowSpinner ] = useState(false); const [ modal, setModal ] = useState(null); @@ -29,6 +29,7 @@ export default ({ uuid }: { uuid: string }) => { const file = ServerContext.useStoreState(state => state.files.contents.find(file => file.uuid === uuid)); const directory = ServerContext.useStoreState(state => state.files.directory); const { removeFile, getDirectoryContents } = ServerContext.useStoreActions(actions => actions.files); + if (!file) { return null; } @@ -87,29 +88,39 @@ export default ({ uuid }: { uuid: string }) => { return (
{ e.preventDefault(); + setModal(null); + if (!visible) { setPosX(e.clientX); - } else if (visible) { - setModal(null); } + setVisible(!visible); }} > {visible && - setModal(null)}/> + { + setModal(null); + setVisible(false); + }} + /> }
setModal('rename')} @@ -118,7 +129,10 @@ export default ({ uuid }: { uuid: string }) => { Rename
-
+
setModal('move')} + className={'hover:text-neutral-700 p-2 flex items-center hover:bg-neutral-100 rounded'} + > Move
diff --git a/resources/scripts/components/server/files/RenameFileModal.tsx b/resources/scripts/components/server/files/RenameFileModal.tsx index 5b97d0e4e..2943d002b 100644 --- a/resources/scripts/components/server/files/RenameFileModal.tsx +++ b/resources/scripts/components/server/files/RenameFileModal.tsx @@ -6,14 +6,15 @@ import { join } from 'path'; import renameFile from '@/api/server/files/renameFile'; import { ServerContext } from '@/state/server'; import { FileObject } from '@/api/server/files/loadDirectory'; +import classNames from 'classnames'; interface FormikValues { name: string; } -type Props = RequiredModalProps & { file: FileObject }; +type Props = RequiredModalProps & { file: FileObject; useMoveTerminology?: boolean }; -export default ({ file, ...props }: Props) => { +export default ({ file, useMoveTerminology, ...props }: Props) => { const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const directory = ServerContext.useStoreState(state => state.files.directory); const pushFile = ServerContext.useStoreActions(actions => actions.files.pushFile); @@ -38,22 +39,36 @@ export default ({ file, ...props }: Props) => { onSubmit={submit} initialValues={{ name: file.name }} > - {({ isSubmitting }) => ( + {({ isSubmitting, values }) => (
- -
- +
+
+ +
+
+ +
+

+ New location: +  /home/container/{join(directory, values.name).replace(/^(\.\.\/|\/)+/, '')} +

)}