From 14c587eabea5097f9ab5e31530998ed6769f938c Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 6 Aug 2020 20:33:17 -0700 Subject: [PATCH] Correctly inject new directory into file manager --- .../server/files/NewDirectoryButton.tsx | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/resources/scripts/components/server/files/NewDirectoryButton.tsx b/resources/scripts/components/server/files/NewDirectoryButton.tsx index 27cfb15f7..0a6a2b07f 100644 --- a/resources/scripts/components/server/files/NewDirectoryButton.tsx +++ b/resources/scripts/components/server/files/NewDirectoryButton.tsx @@ -8,11 +8,10 @@ import { object, string } from 'yup'; import createDirectory from '@/api/server/files/createDirectory'; import tw from 'twin.macro'; import Button from '@/components/elements/Button'; -import { mutate } from 'swr'; import useServer from '@/plugins/useServer'; import { FileObject } from '@/api/server/files/loadDirectory'; -import { useLocation } from 'react-router'; import useFlash from '@/plugins/useFlash'; +import useFileManagerSwr from '@/plugins/useFileManagerSwr'; interface Values { directoryName: string; @@ -38,20 +37,16 @@ const generateDirectoryData = (name: string): FileObject => ({ export default () => { const { uuid } = useServer(); - const { hash } = useLocation(); const { clearAndAddHttpError } = useFlash(); const [ visible, setVisible ] = useState(false); + + const { mutate } = useFileManagerSwr(); const directory = ServerContext.useStoreState(state => state.files.directory); const submit = ({ directoryName }: Values, { setSubmitting }: FormikHelpers) => { createDirectory(uuid, directory, directoryName) - .then(() => { - mutate( - `${uuid}:files:${hash}`, - (data: FileObject[]) => [ ...data, generateDirectoryData(directoryName) ], - ); - setVisible(false); - }) + .then(() => mutate(data => [ ...data, generateDirectoryData(directoryName) ], false)) + .then(() => setVisible(false)) .catch(error => { console.error(error); setSubmitting(false); @@ -78,6 +73,7 @@ export default () => { >