From e066ee5ff1f96c727a02459a83176d083c088107 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 20 Dec 2021 12:59:39 +0530 Subject: [PATCH 1/3] added start and finish loading helper function --- src/pages/gallery/index.tsx | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 3f3976357..df8bf8982 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -362,12 +362,17 @@ export default function Gallery() { setSelected({ count: 0, collectionID: 0 }); }; + const startLoading = () => + !syncInProgress.current && loadingBar.current?.continuousStart(); + const finishLoading = () => + !syncInProgress.current && loadingBar.current.complete(); + if (!files) { return
; } const collectionOpsHelper = (ops: COLLECTION_OPS_TYPE) => async (collection: Collection) => { - loadingBar.current?.continuousStart(); + startLoading(); try { await handleCollectionOps( ops, @@ -388,14 +393,14 @@ export default function Gallery() { }); } finally { await syncWithRemote(false, true); - loadingBar.current.complete(); + finishLoading(); } }; const changeFilesVisibilityHelper = async ( visibility: VISIBILITY_STATE ) => { - loadingBar.current?.continuousStart(); + startLoading(); try { const updatedFiles = await changeFilesVisibility( files, @@ -424,7 +429,7 @@ export default function Gallery() { }); } finally { await syncWithRemote(false, true); - loadingBar.current.complete(); + finishLoading(); } }; @@ -458,7 +463,7 @@ export default function Gallery() { }; const deleteFileHelper = async (permanent?: boolean) => { - loadingBar.current?.continuousStart(); + startLoading(); try { const selectedFiles = getSelectedFiles(selected, files); if (permanent) { @@ -489,7 +494,7 @@ export default function Gallery() { }); } finally { await syncWithRemote(false, true); - loadingBar.current.complete(); + finishLoading(); } }; @@ -519,7 +524,7 @@ export default function Gallery() { close: { text: constants.CANCEL }, }); const emptyTrashHelper = async () => { - loadingBar.current?.continuousStart(); + startLoading(); try { await emptyTrash(); if (selected.collectionID === TRASH_SECTION) { @@ -536,7 +541,7 @@ export default function Gallery() { }); } finally { await syncWithRemote(false, true); - loadingBar.current.complete(); + finishLoading(); } }; @@ -549,9 +554,9 @@ export default function Gallery() { const downloadHelper = async () => { const selectedFiles = getSelectedFiles(selected, files); clearSelection(); - !syncInProgress.current && loadingBar.current?.continuousStart(); + startLoading(); await downloadFiles(selectedFiles); - !syncInProgress.current && loadingBar.current.complete(); + finishLoading(); }; return ( @@ -609,7 +614,8 @@ export default function Gallery() { syncWithRemote={syncWithRemote} setDialogMessage={setDialogMessage} setCollectionNamerAttributes={setCollectionNamerAttributes} - startLoadingBar={loadingBar.current?.continuousStart} + startLoading={startLoading} + finishLoading={finishLoading} collectionFilesCount={collectionFilesCount} /> Date: Mon, 20 Dec 2021 13:00:56 +0530 Subject: [PATCH 2/3] adds download collection option --- .../pages/gallery/CollectionOptions.tsx | 45 ++++++++++++++++--- src/components/pages/gallery/Collections.tsx | 6 ++- src/utils/collection/index.ts | 27 ++++++++++- src/utils/strings/englishConstants.tsx | 8 ++++ 4 files changed, 76 insertions(+), 10 deletions(-) diff --git a/src/components/pages/gallery/CollectionOptions.tsx b/src/components/pages/gallery/CollectionOptions.tsx index 041d58f07..e34be88f4 100644 --- a/src/components/pages/gallery/CollectionOptions.tsx +++ b/src/components/pages/gallery/CollectionOptions.tsx @@ -6,18 +6,20 @@ import { deleteCollection, renameCollection, } from 'services/collectionService'; -import { getSelectedCollection } from 'utils/collection'; +import { downloadCollection, getSelectedCollection } from 'utils/collection'; import constants from 'utils/strings/constants'; import { SetCollectionNamerAttributes } from './CollectionNamer'; import LinkButton, { ButtonVariant, LinkButtonProps } from './LinkButton'; +import { sleep } from 'utils/common'; -interface Props { +interface CollectionOptionsProps { syncWithRemote: () => Promise; setCollectionNamerAttributes: SetCollectionNamerAttributes; collections: Collection[]; selectedCollectionID: number; setDialogMessage: SetDialogMessage; - startLoadingBar: () => void; + startLoading: () => void; + finishLoading: () => void; showCollectionShareModal: () => void; redirectToAll: () => void; } @@ -43,7 +45,7 @@ export const MenuItem = (props: { children: any }) => ( ); -const CollectionOptions = (props: Props) => { +const CollectionOptions = (props: CollectionOptionsProps) => { const collectionRename = async ( selectedCollection: Collection, newName: string @@ -62,7 +64,7 @@ const CollectionOptions = (props: Props) => { props.collections )?.name, callback: (newName) => { - props.startLoadingBar(); + props.startLoading(); collectionRename( getSelectedCollection( props.selectedCollectionID, @@ -81,7 +83,7 @@ const CollectionOptions = (props: Props) => { proceed: { text: constants.DELETE_COLLECTION, action: () => { - props.startLoadingBar(); + props.startLoading(); deleteCollection( props.selectedCollectionID, props.syncWithRemote, @@ -97,6 +99,32 @@ const CollectionOptions = (props: Props) => { }); }; + const confirmDownloadCollection = () => { + props.setDialogMessage({ + title: constants.CONFIRM_DOWNLOAD_COLLECTION, + content: constants.DOWNLOAD_COLLECTION_MESSAGE(), + staticBackdrop: true, + proceed: { + text: constants.DOWNLOAD, + action: downloadCollectionHelper, + variant: 'success', + }, + close: { + text: constants.CANCEL, + }, + }); + }; + + const downloadCollectionHelper = async () => { + props.startLoading(); + await downloadCollection( + props.selectedCollectionID, + props.setDialogMessage + ); + await sleep(1000); + props.finishLoading(); + }; + return ( @@ -111,6 +139,11 @@ const CollectionOptions = (props: Props) => { {constants.SHARE} + + + {constants.DOWNLOAD} + + Promise; setCollectionNamerAttributes: SetCollectionNamerAttributes; - startLoadingBar: () => void; + startLoading: () => void; + finishLoading: () => void; isInSearchMode: boolean; collectionFilesCount: Map; } @@ -169,7 +170,8 @@ export default function Collections(props: CollectionProps) { collections: props.collections, selectedCollectionID, setDialogMessage: props.setDialogMessage, - startLoadingBar: props.startLoadingBar, + startLoading: props.startLoading, + finishLoading: props.finishLoading, showCollectionShareModal: setCollectionShareModalView.bind(null, true), redirectToAll: setActiveCollection.bind(null, ALL_SECTION), }); diff --git a/src/utils/collection/index.ts b/src/utils/collection/index.ts index 506344deb..46aae90e9 100644 --- a/src/utils/collection/index.ts +++ b/src/utils/collection/index.ts @@ -6,12 +6,15 @@ import { removeFromCollection, restoreToCollection, } from 'services/collectionService'; -import { getSelectedFiles } from 'utils/file'; -import { File } from 'services/fileService'; +import { downloadFiles, getSelectedFiles } from 'utils/file'; +import { File, getLocalFiles } from 'services/fileService'; import { CustomError } from 'utils/common/errorUtil'; import { SelectedState } from 'pages/gallery'; import { User } from 'services/userService'; import { getData, LS_KEYS } from 'utils/storage/localStorage'; +import { SetDialogMessage } from 'components/MessageDialog'; +import { logError } from 'utils/sentry'; +import constants from 'utils/strings/constants'; export enum COLLECTION_OPS_TYPE { ADD, @@ -83,3 +86,23 @@ export function isFavoriteCollection( return collection.type === CollectionType.favorites; } } + +export async function downloadCollection( + collectionID: number, + setDialogMessage: SetDialogMessage +) { + try { + const allFiles = await getLocalFiles(); + const collectionFiles = allFiles.filter( + (file) => file.collectionID === collectionID + ); + await downloadFiles(collectionFiles); + } catch (e) { + logError(e, 'download collection failed '); + setDialogMessage({ + title: constants.ERROR, + content: constants.DELETE_COLLECTION_FAILED, + close: { variant: 'danger' }, + }); + } +} diff --git a/src/utils/strings/englishConstants.tsx b/src/utils/strings/englishConstants.tsx index 27e82c1aa..e64872c3b 100644 --- a/src/utils/strings/englishConstants.tsx +++ b/src/utils/strings/englishConstants.tsx @@ -382,6 +382,14 @@ const englishConstants = { `oops, you're already sharing this with ${email}`, SHARING_BAD_REQUEST_ERROR: 'sharing album not allowed', SHARING_DISABLED_FOR_FREE_ACCOUNTS: 'sharing is disabled for free accounts', + CONFIRM_DOWNLOAD_COLLECTION: 'download album', + DOWNLOAD_COLLECTION_MESSAGE: () => ( + <> +

are you sure you want to download the complete album?

+

all files will be queued for download sententially

+ + ), + DOWNLOAD_COLLECTION_FAILED: 'album downloading failed, please try again', CREATE_ALBUM_FAILED: 'failed to create album , please try again', SEARCH_HINT: () => ( try searching for New York, April 14, Christmas... From 40058f08839d5f22fafd56e5b83ed25ec6dcede9 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 20 Dec 2021 13:21:12 +0530 Subject: [PATCH 3/3] fix typo --- src/utils/strings/englishConstants.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/strings/englishConstants.tsx b/src/utils/strings/englishConstants.tsx index e64872c3b..7ada30d45 100644 --- a/src/utils/strings/englishConstants.tsx +++ b/src/utils/strings/englishConstants.tsx @@ -386,7 +386,7 @@ const englishConstants = { DOWNLOAD_COLLECTION_MESSAGE: () => ( <>

are you sure you want to download the complete album?

-

all files will be queued for download sententially

+

all files will be queued for download sequentially

), DOWNLOAD_COLLECTION_FAILED: 'album downloading failed, please try again',