Correctly inject new directory into file manager
This commit is contained in:
parent
95e8492c5d
commit
14c587eabe
1 changed files with 6 additions and 10 deletions
|
@ -8,11 +8,10 @@ import { object, string } from 'yup';
|
||||||
import createDirectory from '@/api/server/files/createDirectory';
|
import createDirectory from '@/api/server/files/createDirectory';
|
||||||
import tw from 'twin.macro';
|
import tw from 'twin.macro';
|
||||||
import Button from '@/components/elements/Button';
|
import Button from '@/components/elements/Button';
|
||||||
import { mutate } from 'swr';
|
|
||||||
import useServer from '@/plugins/useServer';
|
import useServer from '@/plugins/useServer';
|
||||||
import { FileObject } from '@/api/server/files/loadDirectory';
|
import { FileObject } from '@/api/server/files/loadDirectory';
|
||||||
import { useLocation } from 'react-router';
|
|
||||||
import useFlash from '@/plugins/useFlash';
|
import useFlash from '@/plugins/useFlash';
|
||||||
|
import useFileManagerSwr from '@/plugins/useFileManagerSwr';
|
||||||
|
|
||||||
interface Values {
|
interface Values {
|
||||||
directoryName: string;
|
directoryName: string;
|
||||||
|
@ -38,20 +37,16 @@ const generateDirectoryData = (name: string): FileObject => ({
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const { uuid } = useServer();
|
const { uuid } = useServer();
|
||||||
const { hash } = useLocation();
|
|
||||||
const { clearAndAddHttpError } = useFlash();
|
const { clearAndAddHttpError } = useFlash();
|
||||||
const [ visible, setVisible ] = useState(false);
|
const [ visible, setVisible ] = useState(false);
|
||||||
|
|
||||||
|
const { mutate } = useFileManagerSwr();
|
||||||
const directory = ServerContext.useStoreState(state => state.files.directory);
|
const directory = ServerContext.useStoreState(state => state.files.directory);
|
||||||
|
|
||||||
const submit = ({ directoryName }: Values, { setSubmitting }: FormikHelpers<Values>) => {
|
const submit = ({ directoryName }: Values, { setSubmitting }: FormikHelpers<Values>) => {
|
||||||
createDirectory(uuid, directory, directoryName)
|
createDirectory(uuid, directory, directoryName)
|
||||||
.then(() => {
|
.then(() => mutate(data => [ ...data, generateDirectoryData(directoryName) ], false))
|
||||||
mutate(
|
.then(() => setVisible(false))
|
||||||
`${uuid}:files:${hash}`,
|
|
||||||
(data: FileObject[]) => [ ...data, generateDirectoryData(directoryName) ],
|
|
||||||
);
|
|
||||||
setVisible(false);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
|
@ -78,6 +73,7 @@ export default () => {
|
||||||
>
|
>
|
||||||
<Form css={tw`m-0`}>
|
<Form css={tw`m-0`}>
|
||||||
<Field
|
<Field
|
||||||
|
autoFocus
|
||||||
id={'directoryName'}
|
id={'directoryName'}
|
||||||
name={'directoryName'}
|
name={'directoryName'}
|
||||||
label={'Directory Name'}
|
label={'Directory Name'}
|
||||||
|
|
Loading…
Reference in a new issue