diff --git a/products/ASC.Files/Client/src/store/FilesActionsStore.js b/products/ASC.Files/Client/src/store/FilesActionsStore.js index da21f310cba..c1989f2cdcf 100644 --- a/products/ASC.Files/Client/src/store/FilesActionsStore.js +++ b/products/ASC.Files/Client/src/store/FilesActionsStore.js @@ -56,15 +56,30 @@ class FilesActionStore { } }; - updateCurrentFolder = () => { + updateCurrentFolder = (selectionLength) => { const { clearSecondaryProgressData, } = this.uploadDataStore.secondaryProgressDataStore; - const { filter, fetchFiles } = this.filesStore; - fetchFiles(this.selectedFolderStore.id, filter, true, true).finally(() => - setTimeout(() => clearSecondaryProgressData(), TIMEOUT) - ); + const { + filter, + fetchFiles, + isEmptyLastPageAfterOperation, + resetFilterPage, + } = this.filesStore; + + let newFilter; + + if (selectionLength && isEmptyLastPageAfterOperation(selectionLength)) { + newFilter = resetFilterPage(); + } + + fetchFiles( + this.selectedFolderStore.id, + newFilter ? newFilter : filter, + true, + true + ).finally(() => setTimeout(() => clearSecondaryProgressData(), TIMEOUT)); }; deleteAction = async (translations, newSelection = null) => { @@ -113,7 +128,7 @@ class FilesActionStore { label: translations.deleteOperation, }; await this.uploadDataStore.loopFilesOperations(data, pbData); - this.updateCurrentFolder(); + this.updateCurrentFolder(selection.length); } ); } catch (err) { @@ -332,13 +347,15 @@ class FilesActionStore { label: translations.deleteOperation, }; + const selectionFilesLength = 1; + if (isFile) { this.isMediaOpen(); return deleteFile(itemId) .then(async (res) => { const data = res[0] ? res[0] : null; await this.uploadDataStore.loopFilesOperations(data, pbData); - this.updateCurrentFolder(); + this.updateCurrentFolder(selectionFilesLength); }) .then(() => toastr.success(translations.successRemoveFile)); } else { @@ -346,7 +363,7 @@ class FilesActionStore { .then(async (res) => { const data = res[0] ? res[0] : null; await this.uploadDataStore.loopFilesOperations(data, pbData); - this.updateCurrentFolder(); + this.updateCurrentFolder(selectionFilesLength); }) .then(() => toastr.success(translations.successRemoveFolder)); } diff --git a/products/ASC.Files/Client/src/store/FilesStore.js b/products/ASC.Files/Client/src/store/FilesStore.js index 4c3bde7f87b..62cb4f514c4 100644 --- a/products/ASC.Files/Client/src/store/FilesStore.js +++ b/products/ASC.Files/Client/src/store/FilesStore.js @@ -272,6 +272,26 @@ class FilesStore { ); }; + isEmptyLastPageAfterOperation = (newSelection) => { + const selection = + newSelection || this.selection?.length || [this.bufferSelection].length; + + return ( + selection && + this.filter.page > 0 && + !this.filter.hasNext() && + selection === this.files.length + this.folders.length + ); + }; + + resetFilterPage = () => { + let newFilter; + newFilter = this.filter.clone(); + newFilter.page--; + + return newFilter; + }; + fetchFiles = ( folderId, filter, diff --git a/products/ASC.Files/Client/src/store/UploadDataStore.js b/products/ASC.Files/Client/src/store/UploadDataStore.js index 36a04e7c00f..15551111eb7 100644 --- a/products/ASC.Files/Client/src/store/UploadDataStore.js +++ b/products/ASC.Files/Client/src/store/UploadDataStore.js @@ -979,7 +979,13 @@ class UploadDataStore { moveToCopyTo = (destFolderId, pbData, isCopy) => { const { treeFolders, setTreeFolders } = this.treeFoldersStore; - const { fetchFiles, filter } = this.filesStore; + const { + fetchFiles, + filter, + isEmptyLastPageAfterOperation, + resetFilterPage, + } = this.filesStore; + const { clearSecondaryProgressData, setSecondaryProgressBarData, @@ -994,11 +1000,20 @@ class UploadDataStore { loopTreeFolders(path, newTreeFolders, folders, foldersCount); if (!isCopy || destFolderId === this.selectedFolderStore.id) { - fetchFiles(this.selectedFolderStore.id, filter, true, true).finally( - () => { - setTimeout(() => clearSecondaryProgressData(), TIMEOUT); - } - ); + let newFilter; + + if (isEmptyLastPageAfterOperation()) { + newFilter = resetFilterPage(); + } + + fetchFiles( + this.selectedFolderStore.id, + newFilter ? newFilter : filter, + true, + true + ).finally(() => { + setTimeout(() => clearSecondaryProgressData(), TIMEOUT); + }); } else { setSecondaryProgressBarData({ icon: pbData.icon,