@@ -5,7 +5,6 @@ import Field from '@/components/elements/Field';
55import { join } from 'path' ;
66import renameFiles from '@/api/server/files/renameFiles' ;
77import { ServerContext } from '@/state/server' ;
8- import { FileObject } from '@/api/server/files/loadDirectory' ;
98import tw from 'twin.macro' ;
109import Button from '@/components/elements/Button' ;
1110import useServer from '@/plugins/useServer' ;
@@ -16,9 +15,9 @@ interface FormikValues {
1615 name : string ;
1716}
1817
19- type Props = RequiredModalProps & { file : FileObject ; useMoveTerminology ?: boolean } ;
18+ type Props = RequiredModalProps & { files : string [ ] ; useMoveTerminology ?: boolean } ;
2019
21- export default ( { file , useMoveTerminology, ...props } : Props ) => {
20+ export default ( { files , useMoveTerminology, ...props } : Props ) => {
2221 const { uuid } = useServer ( ) ;
2322 const { mutate } = useFileManagerSwr ( ) ;
2423 const { clearFlashes, clearAndAddHttpError } = useFlash ( ) ;
@@ -28,18 +27,24 @@ export default ({ file, useMoveTerminology, ...props }: Props) => {
2827 clearFlashes ( 'files' ) ;
2928
3029 const len = name . split ( '/' ) . length ;
31- if ( ! useMoveTerminology && len === 1 ) {
32- // Rename the file within this directory.
33- mutate ( files => files . map ( f => f . uuid === file . uuid ? { ...f , name } : f ) , false ) ;
34- } else if ( ( useMoveTerminology || len > 1 ) && file . uuid . length ) {
35- // Remove the file from this directory since they moved it elsewhere.
36- mutate ( files => files . filter ( f => f . uuid !== file . uuid ) , false ) ;
30+ if ( files . length === 1 ) {
31+ if ( ! useMoveTerminology && len === 1 ) {
32+ // Rename the file within this directory.
33+ mutate ( data => data . map ( f => f . name === files [ 0 ] ? { ...f , name } : f ) , false ) ;
34+ } else if ( ( useMoveTerminology || len > 1 ) ) {
35+ // Remove the file from this directory since they moved it elsewhere.
36+ mutate ( data => data . filter ( f => f . name !== files [ 0 ] ) , false ) ;
37+ }
3738 }
3839
39- const renameFrom = join ( directory , file . name ) ;
40- const renameTo = join ( directory , name ) ;
40+ let data ;
41+ if ( useMoveTerminology && files . length > 1 ) {
42+ data = files . map ( f => ( { from : f , to : join ( name , f ) } ) ) ;
43+ } else {
44+ data = files . map ( f => ( { from : f , to : name } ) ) ;
45+ }
4146
42- renameFiles ( uuid , directory , [ { renameFrom , renameTo } ] )
47+ renameFiles ( uuid , directory , data )
4348 . then ( ( ) => props . onDismissed ( ) )
4449 . catch ( error => {
4550 mutate ( ) ;
@@ -49,7 +54,7 @@ export default ({ file, useMoveTerminology, ...props }: Props) => {
4954 } ;
5055
5156 return (
52- < Formik onSubmit = { submit } initialValues = { { name : file . name } } >
57+ < Formik onSubmit = { submit } initialValues = { { name : files . length > 1 ? '' : ( files [ 0 ] || '' ) } } >
5358 { ( { isSubmitting, values } ) => (
5459 < Modal { ...props } dismissable = { ! isSubmitting } showSpinnerOverlay = { isSubmitting } >
5560 < Form css = { tw `m-0` } >
0 commit comments