From ea6a2165e29228861e1e5835226ea75959d3ca20 Mon Sep 17 00:00:00 2001 From: abhinav-grd Date: Tue, 21 Sep 2021 16:08:03 +0530 Subject: [PATCH] added Archive logic --- .../pages/gallery/SelectedFileOptions.tsx | 6 +++ src/pages/gallery/index.tsx | 38 +++++++++++++++++- src/utils/file/index.ts | 40 ++++++++++++++++++- 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/src/components/pages/gallery/SelectedFileOptions.tsx b/src/components/pages/gallery/SelectedFileOptions.tsx index 40f5f5c45..c55c96c7f 100644 --- a/src/components/pages/gallery/SelectedFileOptions.tsx +++ b/src/components/pages/gallery/SelectedFileOptions.tsx @@ -8,6 +8,7 @@ import CrossIcon from 'components/icons/CrossIcon'; import AddIcon from 'components/icons/AddIcon'; import { IconButton } from 'components/Container'; import constants from 'utils/strings/constants'; +import Archive from 'components/icons/archive'; interface Props { addToCollectionHelper: (collectionName, collection) => void; @@ -17,6 +18,7 @@ interface Props { deleteFileHelper: () => void; count: number; clearSelection: () => void; + archiveFilesHelper: () => void; } const SelectionBar = styled(Navbar)` @@ -41,6 +43,7 @@ const SelectedFileOptions = ({ deleteFileHelper, count, clearSelection, + archiveFilesHelper, }: Props) => { const addToCollection = () => setCollectionSelectorAttributes({ @@ -72,6 +75,9 @@ const SelectedFileOptions = ({ {count} {constants.SELECTED} + + + diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 25ccc190a..9a08865ff 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -12,6 +12,7 @@ import { getLocalFiles, deleteFiles, syncFiles, + updateMagicMetadata, } from 'services/fileService'; import styled from 'styled-components'; import LoadingBar from 'react-top-loading-bar'; @@ -44,7 +45,11 @@ import { useDropzone } from 'react-dropzone'; import EnteSpinner from 'components/EnteSpinner'; import { LoadingOverlay } from 'components/LoadingOverlay'; import PhotoFrame from 'components/PhotoFrame'; -import { getSelectedFileIds, sortFilesIntoCollections } from 'utils/file'; +import { + archiveFiles, + getSelectedFileIds, + sortFilesIntoCollections, +} from 'utils/file'; import { addFilesToCollection } from 'utils/collection'; import SearchBar, { DateValue } from 'components/SearchBar'; import { Bbox } from 'services/searchService'; @@ -314,6 +319,36 @@ export default function Gallery() { }); } }; + const archiveFilesHelper = async () => { + loadingBar.current?.continuousStart(); + try { + const archivedFiles = await archiveFiles(files, selected); + await updateMagicMetadata(archivedFiles); + setDeleted([...deleted, ...archivedFiles.map((file) => file.id)]); + } 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 showCreateCollectionModal = () => setCollectionNamerAttributes({ @@ -488,6 +523,7 @@ export default function Gallery() { selected.collectionID === activeCollection && (