diff --git a/tdrive/frontend/src/app/features/drive/hooks/use-drive-upload.tsx b/tdrive/frontend/src/app/features/drive/hooks/use-drive-upload.tsx index 33c63afd..e29bfcf0 100644 --- a/tdrive/frontend/src/app/features/drive/hooks/use-drive-upload.tsx +++ b/tdrive/frontend/src/app/features/drive/hooks/use-drive-upload.tsx @@ -55,8 +55,13 @@ export const useDriveUpload = () => { // Upload files into directories logger.debug("Start file uploading") + //create counter to calculate number of uploaded files, and refresh browsing window only when all the files were uploaded + let expectedUploadsCount = 0; + const parentFolder = context.parentId; + let uploadedFilesCount = 0; for (const parentId of Object.keys(filesPerParentId)) { logger.debug(`Upload files for directory ${parentId}`); + expectedUploadsCount += filesPerParentId[parentId].length; await FileUploadService.upload(filesPerParentId[parentId], { context: { companyId: context.companyId, @@ -64,6 +69,7 @@ export const useDriveUpload = () => { }, callback: (file, context) => { logger.debug('created file: ', file); + uploadedFilesCount++; if (file) { create( { @@ -87,10 +93,12 @@ export const useDriveUpload = () => { }, ); } + if (uploadedFilesCount == expectedUploadsCount) { + refresh(parentFolder, true); + } }, }); } - await refresh(context.parentId, true); }; const uploadFromUrl = (