@@ -568,6 +568,73 @@ export function Files() {
568568 [ descendantFolderIdsByFolderId ]
569569 )
570570
571+ const uploadFiles = useCallback (
572+ async ( filesToUpload : File [ ] , targetFolderId = currentFolderId ) => {
573+ if ( ! workspaceId || filesToUpload . length === 0 || ! canEdit ) return
574+
575+ const oversized : string [ ] = [ ]
576+ const sizeFiltered = filesToUpload . filter ( ( f ) => {
577+ if ( f . size > MAX_WORKSPACE_FILE_SIZE ) {
578+ oversized . push ( f . name )
579+ return false
580+ }
581+ return true
582+ } )
583+ if ( oversized . length > 0 ) {
584+ toast . error (
585+ oversized . length === 1
586+ ? `${ oversized [ 0 ] } exceeds the 5 GiB upload limit`
587+ : `${ oversized . length } files exceed the 5 GiB upload limit`
588+ )
589+ }
590+
591+ const unsupported : string [ ] = [ ]
592+ const allowedFiles = sizeFiltered . filter ( ( f ) => {
593+ const ext = getFileExtension ( f . name )
594+ const ok = SUPPORTED_EXTENSIONS . includes ( ext as ( typeof SUPPORTED_EXTENSIONS ) [ number ] )
595+ if ( ! ok ) unsupported . push ( f . name )
596+ return ok
597+ } )
598+
599+ if ( unsupported . length > 0 ) {
600+ logger . warn ( 'Unsupported file types skipped:' , unsupported )
601+ }
602+
603+ if ( allowedFiles . length === 0 ) return
604+
605+ try {
606+ setUploading ( true )
607+ setUploadProgress ( { completed : 0 , total : allowedFiles . length , currentPercent : 0 } )
608+
609+ for ( let i = 0 ; i < allowedFiles . length ; i ++ ) {
610+ try {
611+ await uploadFile . mutateAsync ( {
612+ workspaceId,
613+ file : allowedFiles [ i ] ,
614+ folderId : targetFolderId ,
615+ onProgress : ( { percent } ) => {
616+ setUploadProgress ( ( prev ) => ( { ...prev , currentPercent : percent } ) )
617+ } ,
618+ } )
619+ setUploadProgress ( {
620+ completed : i + 1 ,
621+ total : allowedFiles . length ,
622+ currentPercent : 0 ,
623+ } )
624+ } catch ( err ) {
625+ logger . error ( 'Error uploading file:' , err )
626+ }
627+ }
628+ } catch ( err ) {
629+ logger . error ( 'Error uploading file:' , err )
630+ } finally {
631+ setUploading ( false )
632+ setUploadProgress ( { completed : 0 , total : 0 , currentPercent : 0 } )
633+ }
634+ } ,
635+ [ workspaceId , canEdit , currentFolderId , uploadFile . mutateAsync ]
636+ )
637+
571638 const rowDragDropConfig = useMemo < RowDragDropConfig > (
572639 ( ) => ( {
573640 activeDropTargetId,
@@ -688,70 +755,6 @@ export function Files() {
688755 ]
689756 )
690757
691- async function uploadFiles ( filesToUpload : File [ ] , targetFolderId = currentFolderId ) {
692- if ( ! workspaceId || filesToUpload . length === 0 || ! canEdit ) return
693-
694- const oversized : string [ ] = [ ]
695- const sizeFiltered = filesToUpload . filter ( ( f ) => {
696- if ( f . size > MAX_WORKSPACE_FILE_SIZE ) {
697- oversized . push ( f . name )
698- return false
699- }
700- return true
701- } )
702- if ( oversized . length > 0 ) {
703- toast . error (
704- oversized . length === 1
705- ? `${ oversized [ 0 ] } exceeds the 5 GiB upload limit`
706- : `${ oversized . length } files exceed the 5 GiB upload limit`
707- )
708- }
709-
710- const unsupported : string [ ] = [ ]
711- const allowedFiles = sizeFiltered . filter ( ( f ) => {
712- const ext = getFileExtension ( f . name )
713- const ok = SUPPORTED_EXTENSIONS . includes ( ext as ( typeof SUPPORTED_EXTENSIONS ) [ number ] )
714- if ( ! ok ) unsupported . push ( f . name )
715- return ok
716- } )
717-
718- if ( unsupported . length > 0 ) {
719- logger . warn ( 'Unsupported file types skipped:' , unsupported )
720- }
721-
722- if ( allowedFiles . length === 0 ) return
723-
724- try {
725- setUploading ( true )
726- setUploadProgress ( { completed : 0 , total : allowedFiles . length , currentPercent : 0 } )
727-
728- for ( let i = 0 ; i < allowedFiles . length ; i ++ ) {
729- try {
730- await uploadFile . mutateAsync ( {
731- workspaceId,
732- file : allowedFiles [ i ] ,
733- folderId : targetFolderId ,
734- onProgress : ( { percent } ) => {
735- setUploadProgress ( ( prev ) => ( { ...prev , currentPercent : percent } ) )
736- } ,
737- } )
738- setUploadProgress ( {
739- completed : i + 1 ,
740- total : allowedFiles . length ,
741- currentPercent : 0 ,
742- } )
743- } catch ( err ) {
744- logger . error ( 'Error uploading file:' , err )
745- }
746- }
747- } catch ( err ) {
748- logger . error ( 'Error uploading file:' , err )
749- } finally {
750- setUploading ( false )
751- setUploadProgress ( { completed : 0 , total : 0 , currentPercent : 0 } )
752- }
753- }
754-
755758 const handleFileChange = async ( e : React . ChangeEvent < HTMLInputElement > ) => {
756759 const list = e . target . files
757760 if ( ! list || list . length === 0 ) return
@@ -819,12 +822,16 @@ export function Files() {
819822 if ( target . fileIds . includes ( fileIdFromRouteRef . current ?? '' ) ) {
820823 setIsDirty ( false )
821824 setSaveStatus ( 'idle' )
822- router . push ( `/workspace/${ workspaceId } /files` )
825+ router . push (
826+ currentFolderId
827+ ? `/workspace/${ workspaceId } /files?folderId=${ currentFolderId } `
828+ : `/workspace/${ workspaceId } /files`
829+ )
823830 }
824831 } catch ( err ) {
825832 logger . error ( 'Failed to delete file:' , err )
826833 }
827- } , [ workspaceId , router , bulkArchiveItems , deleteFile ] )
834+ } , [ workspaceId , router , currentFolderId , bulkArchiveItems , deleteFile ] )
828835
829836 const isDirtyRef = useRef ( isDirty )
830837 isDirtyRef . current = isDirty
0 commit comments