From ea8fd240b576334a64da56b195702e926b236642 Mon Sep 17 00:00:00 2001 From: abhinav-grd Date: Mon, 27 Sep 2021 09:26:01 +0530 Subject: [PATCH 1/5] moves out clearSelection and syncWithRemote to caller --- src/utils/collection/index.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/utils/collection/index.ts b/src/utils/collection/index.ts index 1c13c40c1..2683236a5 100644 --- a/src/utils/collection/index.ts +++ b/src/utils/collection/index.ts @@ -21,8 +21,6 @@ export async function copyOrMoveFromCollection( setCollectionSelectorView: (value: boolean) => void, selected: SelectedState, files: File[], - clearSelection: () => void, - syncWithRemote: () => Promise, setActiveCollection: (id: number) => void, collectionName: string, existingCollection: Collection @@ -52,8 +50,6 @@ export async function copyOrMoveFromCollection( default: throw Error(CustomError.INVALID_COLLECTION_OPERATION); } - clearSelection(); - await syncWithRemote(); setActiveCollection(collection.id); } From 22d2f623021aad87947a1560fe0cacbc5cd2cdb4 Mon Sep 17 00:00:00 2001 From: abhinav-grd Date: Mon, 27 Sep 2021 09:26:29 +0530 Subject: [PATCH 2/5] clear selection and syncWithRemote in finally section --- src/pages/gallery/index.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 7bb813ed3..c8dbfd908 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -326,8 +326,7 @@ export default function Gallery() { setCollectionSelectorView, selected, files, - clearSelection, - syncWithRemote, + setActiveCollection, collectionName, collection @@ -339,6 +338,10 @@ export default function Gallery() { close: { variant: 'danger' }, content: constants.UNKNOWN_ERROR, }); + } finally { + clearSelection(); + syncWithRemote(false, true); + loadingBar.current.complete(); } }; @@ -353,8 +356,7 @@ export default function Gallery() { setCollectionSelectorView, selected, files, - clearSelection, - syncWithRemote, + setActiveCollection, collectionName, collection @@ -366,6 +368,10 @@ export default function Gallery() { close: { variant: 'danger' }, content: constants.UNKNOWN_ERROR, }); + } finally { + clearSelection(); + syncWithRemote(false, true); + loadingBar.current.complete(); } }; const changeFilesVisibilityHelper = async ( @@ -463,7 +469,7 @@ export default function Gallery() { }); } finally { clearSelection(); - syncWithRemote(); + syncWithRemote(false, true); loadingBar.current.complete(); } }; From 44054e1efef0046af3f179a8ebdb8c84aee0ee66 Mon Sep 17 00:00:00 2001 From: abhinav-grd Date: Mon, 27 Sep 2021 09:30:08 +0530 Subject: [PATCH 3/5] silent sync after archive --- src/pages/gallery/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index c8dbfd908..cb588f718 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -404,7 +404,7 @@ export default function Gallery() { }); } finally { clearSelection(); - syncWithRemote(); + syncWithRemote(false, true); loadingBar.current.complete(); } }; From e0d153e0484ecf4036c02a55d220238ffc0dd07e Mon Sep 17 00:00:00 2001 From: abhinav-grd Date: Mon, 27 Sep 2021 10:23:17 +0530 Subject: [PATCH 4/5] wait for sync before setting operation as completed --- src/pages/gallery/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index cb588f718..057411b12 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -340,7 +340,7 @@ export default function Gallery() { }); } finally { clearSelection(); - syncWithRemote(false, true); + await syncWithRemote(false, true); loadingBar.current.complete(); } }; @@ -370,7 +370,7 @@ export default function Gallery() { }); } finally { clearSelection(); - syncWithRemote(false, true); + await syncWithRemote(false, true); loadingBar.current.complete(); } }; @@ -404,7 +404,7 @@ export default function Gallery() { }); } finally { clearSelection(); - syncWithRemote(false, true); + await syncWithRemote(false, true); loadingBar.current.complete(); } }; @@ -469,7 +469,7 @@ export default function Gallery() { }); } finally { clearSelection(); - syncWithRemote(false, true); + await syncWithRemote(false, true); loadingBar.current.complete(); } }; From 5bd6ba078848510fd720fb1da1e629264c44eb8e Mon Sep 17 00:00:00 2001 From: abhinav-grd Date: Tue, 28 Sep 2021 10:29:43 +0530 Subject: [PATCH 5/5] clear selection only on successful completion of operation --- src/pages/gallery/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 057411b12..5c95b7dd1 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -331,6 +331,7 @@ export default function Gallery() { collectionName, collection ); + clearSelection(); } catch (e) { setDialogMessage({ title: constants.ERROR, @@ -339,7 +340,6 @@ export default function Gallery() { content: constants.UNKNOWN_ERROR, }); } finally { - clearSelection(); await syncWithRemote(false, true); loadingBar.current.complete(); } @@ -361,6 +361,7 @@ export default function Gallery() { collectionName, collection ); + clearSelection(); } catch (e) { setDialogMessage({ title: constants.ERROR, @@ -369,7 +370,6 @@ export default function Gallery() { content: constants.UNKNOWN_ERROR, }); } finally { - clearSelection(); await syncWithRemote(false, true); loadingBar.current.complete(); } @@ -385,6 +385,7 @@ export default function Gallery() { visibility ); await updateMagicMetadata(updatedFiles); + clearSelection(); } catch (e) { switch (e.status?.toString()) { case ServerErrorCodes.FORBIDDEN: @@ -403,7 +404,6 @@ export default function Gallery() { content: constants.UNKNOWN_ERROR, }); } finally { - clearSelection(); await syncWithRemote(false, true); loadingBar.current.complete(); } @@ -451,6 +451,7 @@ export default function Gallery() { const fileIds = getSelectedFileIds(selected); await deleteFiles(fileIds); setDeleted([...deleted, ...fileIds]); + clearSelection(); } catch (e) { switch (e.status?.toString()) { case ServerErrorCodes.FORBIDDEN: @@ -468,7 +469,6 @@ export default function Gallery() { content: constants.UNKNOWN_ERROR, }); } finally { - clearSelection(); await syncWithRemote(false, true); loadingBar.current.complete(); }