Slightly more logical handling when moving things around

This commit is contained in:
Dane Everitt 2019-12-16 19:55:02 -08:00
parent d07ee9a36b
commit 85b47ceb79
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -17,7 +17,7 @@ type Props = RequiredModalProps & { file: FileObject; useMoveTerminology?: boole
export default ({ file, useMoveTerminology, ...props }: Props) => { export default ({ file, useMoveTerminology, ...props }: Props) => {
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
const directory = ServerContext.useStoreState(state => state.files.directory); const directory = ServerContext.useStoreState(state => state.files.directory);
const pushFile = ServerContext.useStoreActions(actions => actions.files.pushFile); const { pushFile, removeFile } = ServerContext.useStoreActions(actions => actions.files);
const submit = (values: FormikValues, { setSubmitting }: FormikActions<FormikValues>) => { const submit = (values: FormikValues, { setSubmitting }: FormikActions<FormikValues>) => {
const renameFrom = join(directory, file.name); const renameFrom = join(directory, file.name);
@ -25,7 +25,14 @@ export default ({ file, useMoveTerminology, ...props }: Props) => {
renameFile(uuid, { renameFrom, renameTo }) renameFile(uuid, { renameFrom, renameTo })
.then(() => { .then(() => {
if (!useMoveTerminology && values.name.split('/').length === 1) {
pushFile({ ...file, name: values.name }); pushFile({ ...file, name: values.name });
}
if ((useMoveTerminology || values.name.split('/').length > 1) && file.uuid.length > 0) {
removeFile(file.uuid);
}
props.onDismissed(); props.onDismissed();
}) })
.catch(error => { .catch(error => {