From 06751821779e14b237c69fb8ac2eedc366491108 Mon Sep 17 00:00:00 2001 From: abhinav-grd Date: Wed, 22 Sep 2021 17:51:52 +0530 Subject: [PATCH] refactor code --- src/pages/gallery/index.tsx | 56 +++++++++++-------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 9faf0aef6..48d49393e 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -370,49 +370,17 @@ export default function Gallery() { }); } }; - const archiveFilesHelper = async () => { + const changeFilesVisibilityHelper = async ( + visibility: VISIBILITY_STATE + ) => { loadingBar.current?.continuousStart(); try { - const archivedFiles = await changeFilesVisibility( + const updatedFiles = await changeFilesVisibility( files, selected, - VISIBILITY_STATE.ARCHIVED + visibility ); - await updateMagicMetadata(archivedFiles); - } catch (e) { - console.log(e); - switch (e.status?.toString()) { - case ServerErrorCodes.FORBIDDEN: - setDialogMessage({ - title: constants.ERROR, - staticBackdrop: true, - close: { variant: 'danger' }, - content: constants.NOT_FILE_OWNER, - }); - return; - } - setDialogMessage({ - title: constants.ERROR, - staticBackdrop: true, - close: { variant: 'danger' }, - content: constants.UNKNOWN_ERROR, - }); - } finally { - clearSelection(); - syncWithRemote(); - loadingBar.current.complete(); - } - }; - - const unArchiveFilesHelper = async () => { - loadingBar.current?.continuousStart(); - try { - const unarchiveFiles = await changeFilesVisibility( - files, - selected, - VISIBILITY_STATE.VISIBLE - ); - await updateMagicMetadata(unarchiveFiles); + await updateMagicMetadata(updatedFiles); } catch (e) { switch (e.status?.toString()) { case ServerErrorCodes.FORBIDDEN: @@ -639,8 +607,16 @@ export default function Gallery() { selected.collectionID === activeCollection && ( + changeFilesVisibilityHelper( + VISIBILITY_STATE.ARCHIVED + ) + } + unArchiveFilesHelper={() => + changeFilesVisibilityHelper( + VISIBILITY_STATE.VISIBLE + ) + } moveToCollectionHelper={moveToCollectionHelper} showCreateCollectionModal={ showCreateCollectionModal