From a221fc9dc1b85f12e67712c99fcf0be485851db1 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Mon, 30 Jan 2023 10:28:51 +0530 Subject: [PATCH 01/33] Added uncategorised section in sidebar --- src/components/Sidebar/ShortcutSection.tsx | 20 +++++++++++++++++++- src/constants/collection/index.ts | 6 +++--- src/pages/gallery/index.tsx | 5 ++++- src/utils/strings/englishConstants.tsx | 1 + 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/components/Sidebar/ShortcutSection.tsx b/src/components/Sidebar/ShortcutSection.tsx index c922453ab..ca880808b 100644 --- a/src/components/Sidebar/ShortcutSection.tsx +++ b/src/components/Sidebar/ShortcutSection.tsx @@ -1,11 +1,16 @@ import React, { useContext } from 'react'; import constants from 'utils/strings/constants'; import { GalleryContext } from 'pages/gallery'; -import { ARCHIVE_SECTION, TRASH_SECTION } from 'constants/collection'; +import { + ARCHIVE_SECTION, + TRASH_SECTION, + UNCATEGORIZED_SECTION, +} from 'constants/collection'; import { CollectionSummaries } from 'types/collection'; import ShortcutButton from './ShortcutButton'; import DeleteOutline from '@mui/icons-material/DeleteOutline'; import ArchiveOutlined from '@mui/icons-material/ArchiveOutlined'; +import CategoryIcon from '@mui/icons-material/Category'; interface Iprops { closeSidebar: () => void; collectionSummaries: CollectionSummaries; @@ -17,6 +22,11 @@ export default function ShortcutSection({ }: Iprops) { const galleryContext = useContext(GalleryContext); + const openUncategorizedSection = () => { + galleryContext.setActiveCollection(UNCATEGORIZED_SECTION); + closeSidebar(); + }; + const openTrashSection = () => { galleryContext.setActiveCollection(TRASH_SECTION); closeSidebar(); @@ -29,6 +39,14 @@ export default function ShortcutSection({ return ( <> + } + label={constants.UNCATEGORIZED} + count={ + collectionSummaries.get(UNCATEGORIZED_SECTION)?.fileCount + } + onClick={openUncategorizedSection} + /> } label={constants.TRASH} diff --git a/src/constants/collection/index.ts b/src/constants/collection/index.ts index af6bff4da..ed18eda49 100644 --- a/src/constants/collection/index.ts +++ b/src/constants/collection/index.ts @@ -1,7 +1,7 @@ -export const ARCHIVE_SECTION = -1; -export const TRASH_SECTION = -2; +export const UNCATEGORIZED_SECTION = -1; +export const ARCHIVE_SECTION = -2; +export const TRASH_SECTION = -3; export const ALL_SECTION = 0; - export enum CollectionType { folder = 'folder', favorites = 'favorites', diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 5cd046f28..ecb1b86c1 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -59,6 +59,7 @@ import PlanSelector from 'components/pages/gallery/PlanSelector'; import Uploader from 'components/Upload/Uploader'; import { ALL_SECTION, + UNCATEGORIZED_SECTION, ARCHIVE_SECTION, CollectionType, TRASH_SECTION, @@ -312,7 +313,9 @@ export default function Gallery() { let collectionURL = ''; if (activeCollection !== ALL_SECTION) { collectionURL += '?collection='; - if (activeCollection === ARCHIVE_SECTION) { + if (activeCollection === UNCATEGORIZED_SECTION) { + collectionURL += constants.UNCATEGORIZED; + } else if (activeCollection === ARCHIVE_SECTION) { collectionURL += constants.ARCHIVE; } else if (activeCollection === TRASH_SECTION) { collectionURL += constants.TRASH; diff --git a/src/utils/strings/englishConstants.tsx b/src/utils/strings/englishConstants.tsx index e55d849af..233fa86ce 100644 --- a/src/utils/strings/englishConstants.tsx +++ b/src/utils/strings/englishConstants.tsx @@ -587,6 +587,7 @@ const englishConstants = { THUMBNAIL_GENERATION_FAILED_INFO: 'These files were uploaded, but unfortunately we could not generate the thumbnails for them.', UPLOAD_TO_COLLECTION: 'Upload to album', + UNCATEGORIZED: 'Uncategorized', ARCHIVE: 'Archive', ARCHIVE_COLLECTION: 'Archive album', ARCHIVE_SECTION_NAME: 'Archive', From 73cec2ef758f42d8b1ae18adb46e9588741395f9 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Mon, 30 Jan 2023 11:02:21 +0530 Subject: [PATCH 02/33] Uncategoried section options and quick options implemented options and quick options are similar to favorites --- ...n.tsx => OnlyDownloadCollectionOption.tsx} | 4 +++- .../CollectionOptions/QuickOptions.tsx | 5 +++- .../Collections/CollectionOptions/index.tsx | 9 +++---- src/constants/collection/index.ts | 5 ++++ src/services/collectionService.ts | 24 +++++++++++++++++++ 5 files changed, 41 insertions(+), 6 deletions(-) rename src/components/Collections/CollectionOptions/{FavoritiesCollectionOption.tsx => OnlyDownloadCollectionOption.tsx} (89%) diff --git a/src/components/Collections/CollectionOptions/FavoritiesCollectionOption.tsx b/src/components/Collections/CollectionOptions/OnlyDownloadCollectionOption.tsx similarity index 89% rename from src/components/Collections/CollectionOptions/FavoritiesCollectionOption.tsx rename to src/components/Collections/CollectionOptions/OnlyDownloadCollectionOption.tsx index a468aa610..13391279d 100644 --- a/src/components/Collections/CollectionOptions/FavoritiesCollectionOption.tsx +++ b/src/components/Collections/CollectionOptions/OnlyDownloadCollectionOption.tsx @@ -12,7 +12,9 @@ interface Iprops { ) => (...args: any[]) => Promise; } -export function FavoritiesCollectionOption({ handleCollectionAction }: Iprops) { +export function OnlyDownloadCollectionOption({ + handleCollectionAction, +}: Iprops) { return ( } diff --git a/src/components/Collections/CollectionOptions/QuickOptions.tsx b/src/components/Collections/CollectionOptions/QuickOptions.tsx index efdaa0e08..164afebdc 100644 --- a/src/components/Collections/CollectionOptions/QuickOptions.tsx +++ b/src/components/Collections/CollectionOptions/QuickOptions.tsx @@ -25,6 +25,7 @@ export function QuickOptions({ {!( collectionSummaryType === CollectionSummaryType.trash || collectionSummaryType === CollectionSummaryType.favorites || + collectionSummaryType === CollectionSummaryType.uncategorized || collectionSummaryType === CollectionSummaryType.incomingShare ) && ( diff --git a/src/components/Collections/CollectionOptions/index.tsx b/src/components/Collections/CollectionOptions/index.tsx index b91d6317c..faf5b7e0b 100644 --- a/src/components/Collections/CollectionOptions/index.tsx +++ b/src/components/Collections/CollectionOptions/index.tsx @@ -18,7 +18,7 @@ import OverflowMenu from 'components/OverflowMenu/menu'; import { CollectionSummaryType } from 'constants/collection'; import { TrashCollectionOption } from './TrashCollectionOption'; import { SharedCollectionOption } from './SharedCollectionOption'; -import { FavoritiesCollectionOption } from './FavoritiesCollectionOption'; +import { OnlyDownloadCollectionOption } from './OnlyDownloadCollectionOption'; import { QuickOptions } from './QuickOptions'; import MoreHoriz from '@mui/icons-material/MoreHoriz'; import { HorizontalFlex } from 'components/Container'; @@ -248,9 +248,10 @@ const CollectionOptions = (props: CollectionOptionsProps) => { - ) : collectionSummaryType === - CollectionSummaryType.favorites ? ( - ) : collectionSummaryType === diff --git a/src/constants/collection/index.ts b/src/constants/collection/index.ts index ed18eda49..f2c41ab09 100644 --- a/src/constants/collection/index.ts +++ b/src/constants/collection/index.ts @@ -14,6 +14,7 @@ export enum CollectionSummaryType { album = 'album', archive = 'archive', trash = 'trash', + uncategorized = 'uncategorized', all = 'all', outgoingShare = 'outgoingShare', incomingShare = 'incomingShare', @@ -41,12 +42,14 @@ export const COLLECTION_SORT_ORDER = new Map([ [CollectionSummaryType.archived, 2], [CollectionSummaryType.archive, 3], [CollectionSummaryType.trash, 4], + [CollectionSummaryType.uncategorized, 4], ]); export const SYSTEM_COLLECTION_TYPES = new Set([ CollectionSummaryType.all, CollectionSummaryType.archive, CollectionSummaryType.trash, + CollectionSummaryType.uncategorized, ]); export const UPLOAD_NOT_ALLOWED_COLLECTION_TYPES = new Set([ @@ -56,6 +59,7 @@ export const UPLOAD_NOT_ALLOWED_COLLECTION_TYPES = new Set([ CollectionSummaryType.outgoingShare, CollectionSummaryType.sharedOnlyViaLink, CollectionSummaryType.trash, + CollectionSummaryType.uncategorized, ]); export const OPTIONS_NOT_HAVING_COLLECTION_TYPES = new Set([ @@ -66,4 +70,5 @@ export const OPTIONS_NOT_HAVING_COLLECTION_TYPES = new Set([ export const HIDE_FROM_COLLECTION_BAR_TYPES = new Set([ CollectionSummaryType.trash, CollectionSummaryType.archive, + CollectionSummaryType.uncategorized, ]); diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index 89d3fc035..a29ccd8b7 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -38,6 +38,7 @@ import { COLLECTION_SORT_ORDER, ALL_SECTION, CollectionSummaryType, + UNCATEGORIZED_SECTION, } from 'constants/collection'; import { NEW_COLLECTION_MAGIC_METADATA, @@ -858,6 +859,14 @@ export function getCollectionSummaries( ) ); + collectionSummaries.set( + UNCATEGORIZED_SECTION, + getUncategorizedCollectionSummaries( + collectionFilesCount, + collectionLatestFiles + ) + ); + return collectionSummaries; } @@ -933,3 +942,18 @@ function getTrashedCollectionSummaries( updationTime: collectionsLatestFile.get(TRASH_SECTION)?.updationTime, }; } + +function getUncategorizedCollectionSummaries( + collectionFilesCount: CollectionFilesCount, + collectionsLatestFile: CollectionLatestFiles +): CollectionSummary { + return { + id: UNCATEGORIZED_SECTION, + name: constants.UNCATEGORIZED, + type: CollectionSummaryType.uncategorized, + latestFile: collectionsLatestFile.get(UNCATEGORIZED_SECTION), + fileCount: collectionFilesCount.get(UNCATEGORIZED_SECTION) ?? 0, + updationTime: collectionsLatestFile.get(UNCATEGORIZED_SECTION) + ?.updationTime, + }; +} From c813a2a93fd5c50ac295e4fb90c321cc390b2b23 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Mon, 30 Jan 2023 11:33:48 +0530 Subject: [PATCH 03/33] updated Remove from Album confirmation --- src/components/pages/gallery/SelectedFileOptions.tsx | 4 ++-- src/utils/strings/englishConstants.tsx | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/pages/gallery/SelectedFileOptions.tsx b/src/components/pages/gallery/SelectedFileOptions.tsx index ae06fa62a..417c74e2d 100644 --- a/src/components/pages/gallery/SelectedFileOptions.tsx +++ b/src/components/pages/gallery/SelectedFileOptions.tsx @@ -94,12 +94,12 @@ const SelectedFileOptions = ({ const removeFromCollectionHandler = () => setDialogMessage({ - title: constants.CONFIRM_REMOVE, + title: constants.REMOVE_FROM_COLLECTION, content: constants.CONFIRM_REMOVE_MESSAGE(), proceed: { action: removeFromCollectionHelper, - text: constants.REMOVE, + text: constants.YES_REMOVE, variant: 'danger', }, close: { text: constants.CANCEL }, diff --git a/src/utils/strings/englishConstants.tsx b/src/utils/strings/englishConstants.tsx index 233fa86ce..5c1bbf53d 100644 --- a/src/utils/strings/englishConstants.tsx +++ b/src/utils/strings/englishConstants.tsx @@ -588,6 +588,7 @@ const englishConstants = { 'These files were uploaded, but unfortunately we could not generate the thumbnails for them.', UPLOAD_TO_COLLECTION: 'Upload to album', UNCATEGORIZED: 'Uncategorized', + MOVE_TO_UNCATEGORIZED: 'Move to uncategorized', ARCHIVE: 'Archive', ARCHIVE_COLLECTION: 'Archive album', ARCHIVE_SECTION_NAME: 'Archive', @@ -599,7 +600,9 @@ const englishConstants = { ADD: 'Add', SORT: 'Sort', REMOVE: 'Remove', + YES_REMOVE: 'Yes, Remove', CONFIRM_REMOVE: 'Confirm removal', + REMOVE_FROM_COLLECTION: 'Remove from album', TRASH: 'Trash', MOVE_TO_TRASH: 'Move to trash', TRASH_FILES_MESSAGE: @@ -623,9 +626,9 @@ const englishConstants = { 'You will leave the album, and it will stop being visible to you.', CONFIRM_REMOVE_MESSAGE: () => ( <> -

Are you sure you want to remove these files from the album?

- All files that are unique to this album will be moved to trash + Selected items will be removed from this album. Items which are + only in this album will be moved to Uncategorized.

), From 2a93b0a873f2e43a82612125ef8a6e6402675b6d Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 30 Jan 2023 13:21:54 +0530 Subject: [PATCH 04/33] change removeFromCollection to moveToUncategorized --- src/constants/collection/index.ts | 4 ++++ src/services/collectionService.ts | 37 +++++++++++++++++++------------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/constants/collection/index.ts b/src/constants/collection/index.ts index f2c41ab09..aeaf58874 100644 --- a/src/constants/collection/index.ts +++ b/src/constants/collection/index.ts @@ -6,6 +6,7 @@ export enum CollectionType { folder = 'folder', favorites = 'favorites', album = 'album', + uncategorized = 'uncategorized', } export enum CollectionSummaryType { @@ -27,6 +28,9 @@ export enum COLLECTION_SORT_BY { UPDATION_TIME_DESCENDING, } +export const UNCATEGORIZED_COLLECTION_NAME = 'Uncategorized'; +export const FAVORITE_COLLECTION_NAME = 'Favorites'; + export const COLLECTION_SHARE_DEFAULT_VALID_DURATION = 10 * 24 * 60 * 60 * 1000 * 1000; export const COLLECTION_SHARE_DEFAULT_DEVICE_LIMIT = 4; diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index a29ccd8b7..f774f8478 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -19,7 +19,6 @@ import { AddToCollectionRequest, MoveToCollectionRequest, EncryptedFileKey, - RemoveFromCollectionRequest, CreatePublicAccessTokenRequest, PublicURL, UpdatePublicURL, @@ -39,6 +38,8 @@ import { ALL_SECTION, CollectionSummaryType, UNCATEGORIZED_SECTION, + UNCATEGORIZED_COLLECTION_NAME, + FAVORITE_COLLECTION_NAME, } from 'constants/collection'; import { NEW_COLLECTION_MAGIC_METADATA, @@ -346,7 +347,7 @@ export const addToFavorites = async (file: EnteFile) => { let favCollection = await getFavCollection(); if (!favCollection) { favCollection = await createCollection( - 'Favorites', + FAVORITE_COLLECTION_NAME, CollectionType.favorites ); const localCollections = await getLocalCollections(); @@ -482,18 +483,8 @@ export const removeFromCollection = async ( files: EnteFile[] ) => { try { - const token = getToken(); - const request: RemoveFromCollectionRequest = { - collectionID: collectionID, - fileIDs: files.map((file) => file.id), - }; - - await HTTPService.post( - `${ENDPOINT}/collections/v2/remove-files`, - request, - null, - { 'X-Auth-Token': token } - ); + const uncategorizedCollection = await getUncategorizedCollection(); + await moveToCollection(uncategorizedCollection, collectionID, files); } catch (e) { logError(e, 'remove from collection failed '); throw e; @@ -957,3 +948,21 @@ function getUncategorizedCollectionSummaries( ?.updationTime, }; } + +async function getUncategorizedCollection(): Promise { + const collections = await getLocalCollections(); + let uncategorizedCollection = collections.find( + (collection) => collection.type === CollectionType.uncategorized + ); + if (!uncategorizedCollection) { + uncategorizedCollection = await createUnCategorizedCollection(); + } + return uncategorizedCollection; +} + +async function createUnCategorizedCollection() { + return createCollection( + UNCATEGORIZED_COLLECTION_NAME, + CollectionType.uncategorized + ); +} From 5e56485a8debf398a524ac3125a93c6462443e4c Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 30 Jan 2023 14:16:17 +0530 Subject: [PATCH 05/33] fix open uncategorized section --- src/components/Sidebar/ShortcutSection.tsx | 6 +++-- src/services/collectionService.ts | 26 +--------------------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/src/components/Sidebar/ShortcutSection.tsx b/src/components/Sidebar/ShortcutSection.tsx index ca880808b..d12e1ee55 100644 --- a/src/components/Sidebar/ShortcutSection.tsx +++ b/src/components/Sidebar/ShortcutSection.tsx @@ -11,6 +11,7 @@ import ShortcutButton from './ShortcutButton'; import DeleteOutline from '@mui/icons-material/DeleteOutline'; import ArchiveOutlined from '@mui/icons-material/ArchiveOutlined'; import CategoryIcon from '@mui/icons-material/Category'; +import { getUncategorizedCollection } from 'services/collectionService'; interface Iprops { closeSidebar: () => void; collectionSummaries: CollectionSummaries; @@ -22,8 +23,9 @@ export default function ShortcutSection({ }: Iprops) { const galleryContext = useContext(GalleryContext); - const openUncategorizedSection = () => { - galleryContext.setActiveCollection(UNCATEGORIZED_SECTION); + const openUncategorizedSection = async () => { + const uncategorisedCollection = await getUncategorizedCollection(); + galleryContext.setActiveCollection(uncategorisedCollection.id); closeSidebar(); }; diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index f774f8478..ba7650de5 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -37,7 +37,6 @@ import { COLLECTION_SORT_ORDER, ALL_SECTION, CollectionSummaryType, - UNCATEGORIZED_SECTION, UNCATEGORIZED_COLLECTION_NAME, FAVORITE_COLLECTION_NAME, } from 'constants/collection'; @@ -850,14 +849,6 @@ export function getCollectionSummaries( ) ); - collectionSummaries.set( - UNCATEGORIZED_SECTION, - getUncategorizedCollectionSummaries( - collectionFilesCount, - collectionLatestFiles - ) - ); - return collectionSummaries; } @@ -934,22 +925,7 @@ function getTrashedCollectionSummaries( }; } -function getUncategorizedCollectionSummaries( - collectionFilesCount: CollectionFilesCount, - collectionsLatestFile: CollectionLatestFiles -): CollectionSummary { - return { - id: UNCATEGORIZED_SECTION, - name: constants.UNCATEGORIZED, - type: CollectionSummaryType.uncategorized, - latestFile: collectionsLatestFile.get(UNCATEGORIZED_SECTION), - fileCount: collectionFilesCount.get(UNCATEGORIZED_SECTION) ?? 0, - updationTime: collectionsLatestFile.get(UNCATEGORIZED_SECTION) - ?.updationTime, - }; -} - -async function getUncategorizedCollection(): Promise { +export async function getUncategorizedCollection(): Promise { const collections = await getLocalCollections(); let uncategorizedCollection = collections.find( (collection) => collection.type === CollectionType.uncategorized From 046d8fb78fc3340f616a51add18d90f308a2e895 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 30 Jan 2023 14:18:01 +0530 Subject: [PATCH 06/33] update removeFromCollection logic --- src/services/collectionService.ts | 21 ++++++++++++++++++++- src/utils/file/index.ts | 12 ++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index ba7650de5..c28848281 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -12,6 +12,7 @@ import { isSharedFile, sortFiles, groupFilesBasedOnCollectionID, + groupFilesBasedOnID, } from 'utils/file'; import { Collection, @@ -56,6 +57,7 @@ import { isSharedOnlyViaLink, } from 'utils/collection'; import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker'; +import { getLocalFiles } from './fileService'; const ENDPOINT = getEndpoint(); const COLLECTION_TABLE = 'collections'; @@ -483,7 +485,24 @@ export const removeFromCollection = async ( ) => { try { const uncategorizedCollection = await getUncategorizedCollection(); - await moveToCollection(uncategorizedCollection, collectionID, files); + const allFiles = await getLocalFiles(); + const groupiedFiles = groupFilesBasedOnID(allFiles); + for (const file of files) { + if (groupiedFiles[file.id].length === 1) { + await moveToCollection(uncategorizedCollection, collectionID, [ + file, + ]); + } else { + const differentCollectionFile = groupiedFiles[file.id].find( + (f) => f.collectionID !== collectionID + ); + const collections = await getLocalCollections(); + const collection = collections.find( + (c) => c.id === differentCollectionFile?.collectionID + ); + await moveToCollection(collection, collectionID, [file]); + } + } } catch (e) { logError(e, 'remove from collection failed '); throw e; diff --git a/src/utils/file/index.ts b/src/utils/file/index.ts index e9b2be105..f01efd297 100644 --- a/src/utils/file/index.ts +++ b/src/utils/file/index.ts @@ -592,3 +592,15 @@ export const copyFileToClipboard = async (fileUrl: string) => { .write([new ClipboardItem({ 'image/png': blobPromise })]) .catch((e) => logError(e, 'failed to copy to clipboard')); }; + +export const groupFilesBasedOnID = (files: EnteFile[]) => { + const groupedFiles = files.reduce((acc, file) => { + if (!acc[file.id]) { + acc[file.id] = []; + } + acc[file.id].push(file); + return acc; + }, {} as { [key: number]: EnteFile[] }); + + return groupedFiles; +}; From c80e3a724c3bbead87842ee42247d21689304ff1 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 30 Jan 2023 14:21:07 +0530 Subject: [PATCH 07/33] update deleteCollection api to v3 --- src/services/collectionService.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index c28848281..dcf075402 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -509,14 +509,17 @@ export const removeFromCollection = async ( } }; -export const deleteCollection = async (collectionID: number) => { +export const deleteCollection = async ( + collectionID: number, + keepPhotos: boolean +) => { try { const token = getToken(); await HTTPService.delete( - `${ENDPOINT}/collections/v2/${collectionID}`, - null, + `${ENDPOINT}/collections/v3/${collectionID}`, null, + { collectionID, keepPhotos }, { 'X-Auth-Token': token } ); } catch (e) { From bb2b78d6ff0d332c11db8ff8148409fdc64943b7 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Mon, 30 Jan 2023 16:23:05 +0530 Subject: [PATCH 08/33] Implemented file selection options for uncategorized files --- .../pages/gallery/SelectedFileOptions.tsx | 15 +++++++++++++++ src/pages/gallery/index.tsx | 5 +++++ src/utils/collection/index.ts | 11 +++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/components/pages/gallery/SelectedFileOptions.tsx b/src/components/pages/gallery/SelectedFileOptions.tsx index 417c74e2d..b214ca35c 100644 --- a/src/components/pages/gallery/SelectedFileOptions.tsx +++ b/src/components/pages/gallery/SelectedFileOptions.tsx @@ -40,6 +40,7 @@ interface Props { unArchiveFilesHelper: () => void; activeCollection: number; isFavoriteCollection: boolean; + isUncategorizedCollection: boolean; } const SelectedFileOptions = ({ @@ -58,6 +59,7 @@ const SelectedFileOptions = ({ unArchiveFilesHelper, activeCollection, isFavoriteCollection, + isUncategorizedCollection, }: Props) => { const { setDialogMessage } = useContext(AppContext); const addToCollection = () => @@ -138,6 +140,19 @@ const SelectedFileOptions = ({
+ ) : isUncategorizedCollection ? ( + <> + + + + + + + + + + + ) : ( <> diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index ecb1b86c1..1deb6a46b 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -73,6 +73,7 @@ import { handleCollectionOps, getSelectedCollection, isFavoriteCollection, + isUncategorizedCollection, getArchivedCollections, hasNonSystemCollections, } from 'utils/collection'; @@ -769,6 +770,10 @@ export default function Gallery() { activeCollection, collections )} + isUncategorizedCollection={isUncategorizedCollection( + activeCollection, + collections + )} /> )} diff --git a/src/utils/collection/index.ts b/src/utils/collection/index.ts index e9cd3d048..de2c63d38 100644 --- a/src/utils/collection/index.ts +++ b/src/utils/collection/index.ts @@ -101,6 +101,17 @@ export function isFavoriteCollection( return collection.type === CollectionType.favorites; } } +export function isUncategorizedCollection( + collectionID: number, + collections: Collection[] +) { + const collection = getSelectedCollection(collectionID, collections); + if (!collection) { + return false; + } else { + return collection.type === CollectionType.uncategorized; + } +} export async function downloadAllCollectionFiles(collectionID: number) { try { From b8faf0d22d13bddb6e56362ed35d0106fca75426 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Tue, 31 Jan 2023 13:01:11 +0530 Subject: [PATCH 09/33] Implemented Keep photos collection action --- .../Collections/CollectionOptions/index.tsx | 13 +++++++++++-- src/utils/strings/englishConstants.tsx | 10 ++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/Collections/CollectionOptions/index.tsx b/src/components/Collections/CollectionOptions/index.tsx index faf5b7e0b..7dad0770e 100644 --- a/src/components/Collections/CollectionOptions/index.tsx +++ b/src/components/Collections/CollectionOptions/index.tsx @@ -40,6 +40,7 @@ export enum CollectionActions { UNARCHIVE, CONFIRM_DELETE, DELETE, + KEEP_PHOTOS, SHOW_SHARE_DIALOG, CONFIRM_EMPTY_TRASH, EMPTY_TRASH, @@ -90,6 +91,9 @@ const CollectionOptions = (props: CollectionOptionsProps) => { case CollectionActions.DELETE: callback = deleteCollection; break; + case CollectionActions.KEEP_PHOTOS: + callback = keepPhotos; + break; case CollectionActions.SHOW_SHARE_DIALOG: callback = showCollectionShareModal; break; @@ -138,7 +142,12 @@ const CollectionOptions = (props: CollectionOptionsProps) => { }; const deleteCollection = async () => { - await CollectionAPI.deleteCollection(activeCollection.id); + await CollectionAPI.deleteCollection(activeCollection.id, false); + redirectToAll(); + }; + + const keepPhotos = async () => { + await CollectionAPI.deleteCollection(activeCollection.id, true); redirectToAll(); }; @@ -177,7 +186,7 @@ const CollectionOptions = (props: CollectionOptionsProps) => { const confirmDeleteCollection = () => { setDialogMessage({ title: constants.DELETE_COLLECTION_TITLE, - content: constants.DELETE_COLLECTION_MESSAGE, + content: constants.DELETE_COLLECTION_MESSAGE(), proceed: { text: constants.DELETE_COLLECTION, action: handleCollectionAction(CollectionActions.DELETE), diff --git a/src/utils/strings/englishConstants.tsx b/src/utils/strings/englishConstants.tsx index 5c1bbf53d..25493c3b4 100644 --- a/src/utils/strings/englishConstants.tsx +++ b/src/utils/strings/englishConstants.tsx @@ -368,8 +368,14 @@ const englishConstants = { DELETE_COLLECTION_TITLE: 'Delete album?', DELETE_COLLECTION: 'Delete album', DELETE_COLLECTION_FAILED: 'Album deletion failed, please try again', - DELETE_COLLECTION_MESSAGE: - 'Files that are unique to this album will be moved to trash, and this album would be deleted.', + DELETE_COLLECTION_MESSAGE: () => ( +

+ Also delete the photos (and videos) present in this album from + all other albums they are part of? +

+ ), + DELETE_PHOTOS: 'Delete photos', + KEEP_PHOTOS: 'Keep photos', SHARE: 'Share', SHARE_COLLECTION: 'Share album', SHARE_WITH_PEOPLE: 'Share with your loved ones', From 3aa3e6b22b47a58cec0be730321a7374a77f0bc3 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Tue, 31 Jan 2023 17:29:39 +0530 Subject: [PATCH 10/33] Removed UNCATEGORIZED_SECTION constant and implemented uncategorized count in side pannel --- src/components/Sidebar/ShortcutSection.tsx | 31 ++++++++++++++-------- src/constants/collection/index.ts | 5 ++-- src/pages/gallery/index.tsx | 5 +--- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/components/Sidebar/ShortcutSection.tsx b/src/components/Sidebar/ShortcutSection.tsx index d12e1ee55..4c7e080c0 100644 --- a/src/components/Sidebar/ShortcutSection.tsx +++ b/src/components/Sidebar/ShortcutSection.tsx @@ -1,11 +1,7 @@ -import React, { useContext } from 'react'; +import React, { useContext, useRef, useEffect } from 'react'; import constants from 'utils/strings/constants'; import { GalleryContext } from 'pages/gallery'; -import { - ARCHIVE_SECTION, - TRASH_SECTION, - UNCATEGORIZED_SECTION, -} from 'constants/collection'; +import { ARCHIVE_SECTION, TRASH_SECTION } from 'constants/collection'; import { CollectionSummaries } from 'types/collection'; import ShortcutButton from './ShortcutButton'; import DeleteOutline from '@mui/icons-material/DeleteOutline'; @@ -22,10 +18,23 @@ export default function ShortcutSection({ collectionSummaries, }: Iprops) { const galleryContext = useContext(GalleryContext); + const unCategorizedCollectionId = useRef(0); + useEffect(() => { + const UncategorizedSection = async () => { + const uncategorisedCollection = await getUncategorizedCollection(); + unCategorizedCollectionId.current = uncategorisedCollection.id; + console.log(unCategorizedCollectionId.current); + console.log('hi'); + }; + return () => { + UncategorizedSection; + }; + }, []); const openUncategorizedSection = async () => { const uncategorisedCollection = await getUncategorizedCollection(); - galleryContext.setActiveCollection(uncategorisedCollection.id); + unCategorizedCollectionId.current = uncategorisedCollection.id; + galleryContext.setActiveCollection(unCategorizedCollectionId.current); closeSidebar(); }; @@ -38,16 +47,16 @@ export default function ShortcutSection({ galleryContext.setActiveCollection(ARCHIVE_SECTION); closeSidebar(); }; - return ( <> } label={constants.UNCATEGORIZED} - count={ - collectionSummaries.get(UNCATEGORIZED_SECTION)?.fileCount - } onClick={openUncategorizedSection} + count={ + collectionSummaries.get(unCategorizedCollectionId.current) + .fileCount + } /> } diff --git a/src/constants/collection/index.ts b/src/constants/collection/index.ts index aeaf58874..2d9f4636e 100644 --- a/src/constants/collection/index.ts +++ b/src/constants/collection/index.ts @@ -1,6 +1,5 @@ -export const UNCATEGORIZED_SECTION = -1; -export const ARCHIVE_SECTION = -2; -export const TRASH_SECTION = -3; +export const ARCHIVE_SECTION = -1; +export const TRASH_SECTION = -2; export const ALL_SECTION = 0; export enum CollectionType { folder = 'folder', diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 1deb6a46b..54082c4e7 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -59,7 +59,6 @@ import PlanSelector from 'components/pages/gallery/PlanSelector'; import Uploader from 'components/Upload/Uploader'; import { ALL_SECTION, - UNCATEGORIZED_SECTION, ARCHIVE_SECTION, CollectionType, TRASH_SECTION, @@ -314,9 +313,7 @@ export default function Gallery() { let collectionURL = ''; if (activeCollection !== ALL_SECTION) { collectionURL += '?collection='; - if (activeCollection === UNCATEGORIZED_SECTION) { - collectionURL += constants.UNCATEGORIZED; - } else if (activeCollection === ARCHIVE_SECTION) { + if (activeCollection === ARCHIVE_SECTION) { collectionURL += constants.ARCHIVE; } else if (activeCollection === TRASH_SECTION) { collectionURL += constants.TRASH; From 0b1b1f8c0947cce3a2961f6341ebfb43963ccf53 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Tue, 31 Jan 2023 18:59:55 +0530 Subject: [PATCH 11/33] Implemented uncategorized count on sidebar --- .../Collections/CollectionOptions/index.tsx | 18 ++++++++++--- src/components/Sidebar/ShortcutSection.tsx | 26 ++++++++----------- src/services/collectionService.ts | 4 +-- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/components/Collections/CollectionOptions/index.tsx b/src/components/Collections/CollectionOptions/index.tsx index 7dad0770e..b8d9d1201 100644 --- a/src/components/Collections/CollectionOptions/index.tsx +++ b/src/components/Collections/CollectionOptions/index.tsx @@ -22,6 +22,7 @@ import { OnlyDownloadCollectionOption } from './OnlyDownloadCollectionOption'; import { QuickOptions } from './QuickOptions'; import MoreHoriz from '@mui/icons-material/MoreHoriz'; import { HorizontalFlex } from 'components/Container'; +import { getLocalFiles } from 'services/fileService'; interface CollectionOptionsProps { setCollectionNamerAttributes: SetCollectionNamerAttributes; @@ -40,7 +41,7 @@ export enum CollectionActions { UNARCHIVE, CONFIRM_DELETE, DELETE, - KEEP_PHOTOS, + KEEP_FILES, SHOW_SHARE_DIALOG, CONFIRM_EMPTY_TRASH, EMPTY_TRASH, @@ -91,8 +92,8 @@ const CollectionOptions = (props: CollectionOptionsProps) => { case CollectionActions.DELETE: callback = deleteCollection; break; - case CollectionActions.KEEP_PHOTOS: - callback = keepPhotos; + case CollectionActions.KEEP_FILES: + callback = keepFiles; break; case CollectionActions.SHOW_SHARE_DIALOG: callback = showCollectionShareModal; @@ -146,7 +147,16 @@ const CollectionOptions = (props: CollectionOptionsProps) => { redirectToAll(); }; - const keepPhotos = async () => { + const keepFiles = async () => { + const allFiles = await getLocalFiles(); + const collectionFiles = allFiles.filter((file) => { + return file.collectionID === activeCollection.id; + }); + await CollectionAPI.removeFromCollection( + activeCollection.id, + collectionFiles + ); + console.log(collectionFiles); await CollectionAPI.deleteCollection(activeCollection.id, true); redirectToAll(); }; diff --git a/src/components/Sidebar/ShortcutSection.tsx b/src/components/Sidebar/ShortcutSection.tsx index 4c7e080c0..6d62b924e 100644 --- a/src/components/Sidebar/ShortcutSection.tsx +++ b/src/components/Sidebar/ShortcutSection.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useRef, useEffect } from 'react'; +import React, { useContext, useState, useEffect } from 'react'; import constants from 'utils/strings/constants'; import { GalleryContext } from 'pages/gallery'; import { ARCHIVE_SECTION, TRASH_SECTION } from 'constants/collection'; @@ -18,23 +18,19 @@ export default function ShortcutSection({ collectionSummaries, }: Iprops) { const galleryContext = useContext(GalleryContext); - const unCategorizedCollectionId = useRef(0); + const [unCategorizedCollectionId, setUncategorezedId] = useState(); useEffect(() => { - const UncategorizedSection = async () => { - const uncategorisedCollection = await getUncategorizedCollection(); - unCategorizedCollectionId.current = uncategorisedCollection.id; - console.log(unCategorizedCollectionId.current); - console.log('hi'); - }; - return () => { - UncategorizedSection; + const main = async () => { + const unCategorisedCollection = await getUncategorizedCollection(); + setUncategorezedId(unCategorisedCollection.id); }; + main(); }, []); const openUncategorizedSection = async () => { - const uncategorisedCollection = await getUncategorizedCollection(); - unCategorizedCollectionId.current = uncategorisedCollection.id; - galleryContext.setActiveCollection(unCategorizedCollectionId.current); + // const uncategorisedCollection = await getUncategorizedCollection(); + // unCategorizedCollectionId.current = uncategorisedCollection.id; + galleryContext.setActiveCollection(unCategorizedCollectionId); closeSidebar(); }; @@ -54,8 +50,8 @@ export default function ShortcutSection({ label={constants.UNCATEGORIZED} onClick={openUncategorizedSection} count={ - collectionSummaries.get(unCategorizedCollectionId.current) - .fileCount + collectionSummaries.get(unCategorizedCollectionId) + ?.fileCount } /> { try { const token = getToken(); @@ -519,7 +519,7 @@ export const deleteCollection = async ( await HTTPService.delete( `${ENDPOINT}/collections/v3/${collectionID}`, null, - { collectionID, keepPhotos }, + { collectionID, keepFiles }, { 'X-Auth-Token': token } ); } catch (e) { From 8ae4a4a8acbac5a5473ff73fe12d44669222a99e Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Tue, 31 Jan 2023 20:50:23 +0530 Subject: [PATCH 12/33] Changed delete album dialogbox in album delete option --- .../Collections/CollectionOptions/index.tsx | 5 +++++ src/components/DialogBox/index.tsx | 12 ++++++++++++ src/types/dialogBox/index.ts | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/src/components/Collections/CollectionOptions/index.tsx b/src/components/Collections/CollectionOptions/index.tsx index b8d9d1201..31d0d8e2f 100644 --- a/src/components/Collections/CollectionOptions/index.tsx +++ b/src/components/Collections/CollectionOptions/index.tsx @@ -202,6 +202,11 @@ const CollectionOptions = (props: CollectionOptionsProps) => { action: handleCollectionAction(CollectionActions.DELETE), variant: 'danger', }, + secondary: { + text: constants.KEEP_PHOTOS, + action: handleCollectionAction(CollectionActions.KEEP_FILES), + variant: 'primary', + }, close: { text: constants.CANCEL, }, diff --git a/src/components/DialogBox/index.tsx b/src/components/DialogBox/index.tsx index fce23fd69..86c19310a 100644 --- a/src/components/DialogBox/index.tsx +++ b/src/components/DialogBox/index.tsx @@ -96,6 +96,18 @@ export default function DialogBox({ {attributes.proceed.text} )} + {attributes.secondary && ( + + )} )} diff --git a/src/types/dialogBox/index.ts b/src/types/dialogBox/index.ts index 4350c3388..0cbc20d30 100644 --- a/src/types/dialogBox/index.ts +++ b/src/types/dialogBox/index.ts @@ -17,6 +17,12 @@ export interface DialogBoxAttributes { variant: ButtonProps['color']; disabled?: boolean; }; + secondary?: { + text: string; + action: () => void; + variant: ButtonProps['color']; + disabled?: boolean; + }; } export type SetDialogBoxAttributes = React.Dispatch< From ab42e68285eab3b1dfc2171b9a01d63685c66653 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Tue, 31 Jan 2023 21:20:07 +0530 Subject: [PATCH 13/33] Customized download option text in OnlyDownloadCollectionOption --- .../OnlyDownloadCollectionOption.tsx | 4 +++- .../Collections/CollectionOptions/index.tsx | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/Collections/CollectionOptions/OnlyDownloadCollectionOption.tsx b/src/components/Collections/CollectionOptions/OnlyDownloadCollectionOption.tsx index 13391279d..17a375af0 100644 --- a/src/components/Collections/CollectionOptions/OnlyDownloadCollectionOption.tsx +++ b/src/components/Collections/CollectionOptions/OnlyDownloadCollectionOption.tsx @@ -10,10 +10,12 @@ interface Iprops { action: CollectionActions, loader?: boolean ) => (...args: any[]) => Promise; + downloadOptionText?: string; } export function OnlyDownloadCollectionOption({ handleCollectionAction, + downloadOptionText = constants.DOWNLOAD, }: Iprops) { return ( - {constants.DOWNLOAD_COLLECTION} + {downloadOptionText} ); } diff --git a/src/components/Collections/CollectionOptions/index.tsx b/src/components/Collections/CollectionOptions/index.tsx index 31d0d8e2f..2d3a4f605 100644 --- a/src/components/Collections/CollectionOptions/index.tsx +++ b/src/components/Collections/CollectionOptions/index.tsx @@ -272,9 +272,14 @@ const CollectionOptions = (props: CollectionOptionsProps) => { - ) : collectionSummaryType === CollectionSummaryType.favorites || - collectionSummaryType === - CollectionSummaryType.uncategorized ? ( + ) : collectionSummaryType === + CollectionSummaryType.favorites ? ( + + ) : collectionSummaryType === + CollectionSummaryType.uncategorized ? ( From 9ac1f97e400eac3b52e2ff78bfa53ae29e7db319 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Tue, 31 Jan 2023 21:49:59 +0530 Subject: [PATCH 14/33] CollectionOptions: Refactored delete options names --- .../Collections/CollectionOptions/index.tsx | 12 +++++++----- src/components/Sidebar/ShortcutSection.tsx | 4 +--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/Collections/CollectionOptions/index.tsx b/src/components/Collections/CollectionOptions/index.tsx index 2d3a4f605..92a178f27 100644 --- a/src/components/Collections/CollectionOptions/index.tsx +++ b/src/components/Collections/CollectionOptions/index.tsx @@ -41,7 +41,7 @@ export enum CollectionActions { UNARCHIVE, CONFIRM_DELETE, DELETE, - KEEP_FILES, + DELETE_BUT_KEEP_FILES, SHOW_SHARE_DIALOG, CONFIRM_EMPTY_TRASH, EMPTY_TRASH, @@ -92,8 +92,8 @@ const CollectionOptions = (props: CollectionOptionsProps) => { case CollectionActions.DELETE: callback = deleteCollection; break; - case CollectionActions.KEEP_FILES: - callback = keepFiles; + case CollectionActions.DELETE_BUT_KEEP_FILES: + callback = deleteButkeepFiles; break; case CollectionActions.SHOW_SHARE_DIALOG: callback = showCollectionShareModal; @@ -147,7 +147,7 @@ const CollectionOptions = (props: CollectionOptionsProps) => { redirectToAll(); }; - const keepFiles = async () => { + const deleteButkeepFiles = async () => { const allFiles = await getLocalFiles(); const collectionFiles = allFiles.filter((file) => { return file.collectionID === activeCollection.id; @@ -204,7 +204,9 @@ const CollectionOptions = (props: CollectionOptionsProps) => { }, secondary: { text: constants.KEEP_PHOTOS, - action: handleCollectionAction(CollectionActions.KEEP_FILES), + action: handleCollectionAction( + CollectionActions.DELETE_BUT_KEEP_FILES + ), variant: 'primary', }, close: { diff --git a/src/components/Sidebar/ShortcutSection.tsx b/src/components/Sidebar/ShortcutSection.tsx index 6d62b924e..9aa940873 100644 --- a/src/components/Sidebar/ShortcutSection.tsx +++ b/src/components/Sidebar/ShortcutSection.tsx @@ -27,9 +27,7 @@ export default function ShortcutSection({ main(); }, []); - const openUncategorizedSection = async () => { - // const uncategorisedCollection = await getUncategorizedCollection(); - // unCategorizedCollectionId.current = uncategorisedCollection.id; + const openUncategorizedSection = () => { galleryContext.setActiveCollection(unCategorizedCollectionId); closeSidebar(); }; From c54dedb952f695148412fe37733f8f79c2871d44 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Wed, 1 Feb 2023 18:00:54 +0530 Subject: [PATCH 15/33] Changed variable names in CollectionOptions and sidebar shortcutSection --- src/components/Collections/CollectionOptions/index.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/Collections/CollectionOptions/index.tsx b/src/components/Collections/CollectionOptions/index.tsx index 92a178f27..8770926ec 100644 --- a/src/components/Collections/CollectionOptions/index.tsx +++ b/src/components/Collections/CollectionOptions/index.tsx @@ -40,7 +40,7 @@ export enum CollectionActions { ARCHIVE, UNARCHIVE, CONFIRM_DELETE, - DELETE, + DELETE_WITH_FILES, DELETE_BUT_KEEP_FILES, SHOW_SHARE_DIALOG, CONFIRM_EMPTY_TRASH, @@ -89,7 +89,7 @@ const CollectionOptions = (props: CollectionOptionsProps) => { case CollectionActions.CONFIRM_DELETE: callback = confirmDeleteCollection; break; - case CollectionActions.DELETE: + case CollectionActions.DELETE_WITH_FILES: callback = deleteCollection; break; case CollectionActions.DELETE_BUT_KEEP_FILES: @@ -199,7 +199,9 @@ const CollectionOptions = (props: CollectionOptionsProps) => { content: constants.DELETE_COLLECTION_MESSAGE(), proceed: { text: constants.DELETE_COLLECTION, - action: handleCollectionAction(CollectionActions.DELETE), + action: handleCollectionAction( + CollectionActions.DELETE_WITH_FILES + ), variant: 'danger', }, secondary: { From 9ca8240f8d084467baf00b40202eb1f9957502b4 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Wed, 1 Feb 2023 18:02:21 +0530 Subject: [PATCH 16/33] Refactored collectionOptions and sidebar shortcutsection --- .../Collections/CollectionOptions/QuickOptions.tsx | 9 +++++---- .../Collections/CollectionOptions/index.tsx | 12 ++++++------ src/components/Sidebar/ShortcutSection.tsx | 9 +++++---- src/utils/strings/englishConstants.tsx | 3 ++- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/components/Collections/CollectionOptions/QuickOptions.tsx b/src/components/Collections/CollectionOptions/QuickOptions.tsx index 164afebdc..c24862ff3 100644 --- a/src/components/Collections/CollectionOptions/QuickOptions.tsx +++ b/src/components/Collections/CollectionOptions/QuickOptions.tsx @@ -51,10 +51,11 @@ export function QuickOptions({ { callback = confirmDeleteCollection; break; case CollectionActions.DELETE_WITH_FILES: - callback = deleteCollection; + callback = deleteCollectionAlongWithFiles; break; case CollectionActions.DELETE_BUT_KEEP_FILES: - callback = deleteButkeepFiles; + callback = deleteCollectionButKeepFiles; break; case CollectionActions.SHOW_SHARE_DIALOG: callback = showCollectionShareModal; @@ -142,12 +142,12 @@ const CollectionOptions = (props: CollectionOptionsProps) => { } }; - const deleteCollection = async () => { + const deleteCollectionAlongWithFiles = async () => { await CollectionAPI.deleteCollection(activeCollection.id, false); redirectToAll(); }; - const deleteButkeepFiles = async () => { + const deleteCollectionButKeepFiles = async () => { const allFiles = await getLocalFiles(); const collectionFiles = allFiles.filter((file) => { return file.collectionID === activeCollection.id; @@ -156,7 +156,6 @@ const CollectionOptions = (props: CollectionOptionsProps) => { activeCollection.id, collectionFiles ); - console.log(collectionFiles); await CollectionAPI.deleteCollection(activeCollection.id, true); redirectToAll(); }; @@ -280,12 +279,13 @@ const CollectionOptions = (props: CollectionOptionsProps) => { CollectionSummaryType.favorites ? ( ) : collectionSummaryType === CollectionSummaryType.uncategorized ? ( ) : collectionSummaryType === CollectionSummaryType.incomingShare ? ( diff --git a/src/components/Sidebar/ShortcutSection.tsx b/src/components/Sidebar/ShortcutSection.tsx index 9aa940873..3092dfbc9 100644 --- a/src/components/Sidebar/ShortcutSection.tsx +++ b/src/components/Sidebar/ShortcutSection.tsx @@ -18,17 +18,18 @@ export default function ShortcutSection({ collectionSummaries, }: Iprops) { const galleryContext = useContext(GalleryContext); - const [unCategorizedCollectionId, setUncategorezedId] = useState(); + const [uncategorizedCollectionId, setUncategorizedCollectionID] = + useState(); useEffect(() => { const main = async () => { const unCategorisedCollection = await getUncategorizedCollection(); - setUncategorezedId(unCategorisedCollection.id); + setUncategorizedCollectionID(unCategorisedCollection.id); }; main(); }, []); const openUncategorizedSection = () => { - galleryContext.setActiveCollection(unCategorizedCollectionId); + galleryContext.setActiveCollection(uncategorizedCollectionId); closeSidebar(); }; @@ -48,7 +49,7 @@ export default function ShortcutSection({ label={constants.UNCATEGORIZED} onClick={openUncategorizedSection} count={ - collectionSummaries.get(unCategorizedCollectionId) + collectionSummaries.get(uncategorizedCollectionId) ?.fileCount } /> diff --git a/src/utils/strings/englishConstants.tsx b/src/utils/strings/englishConstants.tsx index 25493c3b4..cf9138447 100644 --- a/src/utils/strings/englishConstants.tsx +++ b/src/utils/strings/englishConstants.tsx @@ -140,7 +140,8 @@ const englishConstants = { CREATE: 'Create', DOWNLOAD: 'Download', DOWNLOAD_OPTION: 'Download (D)', - DOWNLOAD_FAVOURITES: 'Download favourites', + DOWNLOAD_FAVORITES: 'Download favorites', + DOWNLOAD_UNCATEGORIZED: 'Download uncategorized', COPY_OPTION: 'Copy as PNG (Ctrl/Cmd - C)', TOGGLE_FULLSCREEN: 'Toggle fullscreen (F)', ZOOM_IN_OUT: 'Zoom in/out', From 38d6d4dbb69bc135c46d49e2b8243427f9fcd5d5 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 1 Feb 2023 18:58:27 +0530 Subject: [PATCH 17/33] show dummy uncategorized until actual is created --- src/components/Sidebar/ShortcutSection.tsx | 14 ++++-- src/constants/collection/index.ts | 1 + src/pages/gallery/index.tsx | 6 ++- src/services/collectionService.ts | 54 +++++++++++++++++----- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/components/Sidebar/ShortcutSection.tsx b/src/components/Sidebar/ShortcutSection.tsx index 3092dfbc9..fdbaeb16b 100644 --- a/src/components/Sidebar/ShortcutSection.tsx +++ b/src/components/Sidebar/ShortcutSection.tsx @@ -1,7 +1,11 @@ import React, { useContext, useState, useEffect } from 'react'; import constants from 'utils/strings/constants'; import { GalleryContext } from 'pages/gallery'; -import { ARCHIVE_SECTION, TRASH_SECTION } from 'constants/collection'; +import { + ARCHIVE_SECTION, + DUMMY_UNCATEGORIZED_SECTION, + TRASH_SECTION, +} from 'constants/collection'; import { CollectionSummaries } from 'types/collection'; import ShortcutButton from './ShortcutButton'; import DeleteOutline from '@mui/icons-material/DeleteOutline'; @@ -22,8 +26,12 @@ export default function ShortcutSection({ useState(); useEffect(() => { const main = async () => { - const unCategorisedCollection = await getUncategorizedCollection(); - setUncategorizedCollectionID(unCategorisedCollection.id); + const unCategorizedCollection = await getUncategorizedCollection(); + if (unCategorizedCollection) { + setUncategorizedCollectionID(unCategorizedCollection.id); + } else { + setUncategorizedCollectionID(DUMMY_UNCATEGORIZED_SECTION); + } }; main(); }, []); diff --git a/src/constants/collection/index.ts b/src/constants/collection/index.ts index 30e697d4e..0d0b9eb88 100644 --- a/src/constants/collection/index.ts +++ b/src/constants/collection/index.ts @@ -1,5 +1,6 @@ export const ARCHIVE_SECTION = -1; export const TRASH_SECTION = -2; +export const DUMMY_UNCATEGORIZED_SECTION = -3; export const ALL_SECTION = 0; export enum CollectionType { folder = 'folder', diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 988494c4b..5ae4445fe 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -61,7 +61,9 @@ import { ALL_SECTION, ARCHIVE_SECTION, CollectionType, + DUMMY_UNCATEGORIZED_SECTION, TRASH_SECTION, + UNCATEGORIZED_COLLECTION_NAME, } from 'constants/collection'; import { AppContext } from 'pages/_app'; import { CustomError, ServerErrorCodes } from 'utils/error'; @@ -327,6 +329,8 @@ export default function Gallery() { collectionURL += constants.ARCHIVE; } else if (activeCollection === TRASH_SECTION) { collectionURL += constants.TRASH; + } else if (activeCollection === DUMMY_UNCATEGORIZED_SECTION) { + collectionURL += UNCATEGORIZED_COLLECTION_NAME; } else { collectionURL += activeCollection; } @@ -409,7 +413,7 @@ export default function Gallery() { const archivedCollections = getArchivedCollections(collections); setArchivedCollections(archivedCollections); - const collectionSummaries = getCollectionSummaries( + const collectionSummaries = await getCollectionSummaries( user, collections, files, diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index 7fb435632..f00e0c34a 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -40,6 +40,7 @@ import { CollectionSummaryType, UNCATEGORIZED_COLLECTION_NAME, FAVORITE_COLLECTION_NAME, + DUMMY_UNCATEGORIZED_SECTION, } from 'constants/collection'; import { NEW_COLLECTION_MAGIC_METADATA, @@ -498,7 +499,10 @@ export const removeFromCollection = async ( files: EnteFile[] ) => { try { - const uncategorizedCollection = await getUncategorizedCollection(); + let uncategorizedCollection = await getUncategorizedCollection(); + if (!uncategorizedCollection) { + uncategorizedCollection = await createUnCategorizedCollection(); + } const allFiles = await getLocalFiles(); const groupiedFiles = groupFilesBasedOnID(allFiles); for (const file of files) { @@ -830,12 +834,12 @@ function compareCollectionsLatestFile(first: EnteFile, second: EnteFile) { } } -export function getCollectionSummaries( +export async function getCollectionSummaries( user: User, collections: Collection[], files: EnteFile[], archivedCollections: Set -): CollectionSummaries { +): Promise { const collectionSummaries: CollectionSummaries = new Map(); const collectionLatestFiles = getCollectionLatestFiles( files, @@ -847,12 +851,15 @@ export function getCollectionSummaries( ); for (const collection of collections) { - if (collectionFilesCount.get(collection.id)) { + if ( + collectionFilesCount.get(collection.id) || + collection.type === CollectionType.uncategorized + ) { collectionSummaries.set(collection.id, { id: collection.id, name: collection.name, latestFile: collectionLatestFiles.get(collection.id), - fileCount: collectionFilesCount.get(collection.id), + fileCount: collectionFilesCount.get(collection.id) ?? 0, updationTime: collection.updationTime, type: isIncomingShare(collection, user) ? CollectionSummaryType.incomingShare @@ -866,6 +873,16 @@ export function getCollectionSummaries( }); } } + const uncategorizedCollection = await getUncategorizedCollection( + collections + ); + + if (!uncategorizedCollection) { + collectionSummaries.set( + DUMMY_UNCATEGORIZED_SECTION, + getDummyUncategorizedCollectionSummaries() + ); + } collectionSummaries.set( ALL_SECTION, getAllCollectionSummaries(collectionFilesCount, collectionLatestFiles) @@ -933,6 +950,17 @@ function getAllCollectionSummaries( }; } +function getDummyUncategorizedCollectionSummaries(): CollectionSummary { + return { + id: ALL_SECTION, + name: UNCATEGORIZED_COLLECTION_NAME, + type: CollectionSummaryType.uncategorized, + latestFile: null, + fileCount: 0, + updationTime: 0, + }; +} + function getArchivedCollectionSummaries( collectionFilesCount: CollectionFilesCount, collectionsLatestFile: CollectionLatestFiles @@ -961,18 +989,20 @@ function getTrashedCollectionSummaries( }; } -export async function getUncategorizedCollection(): Promise { - const collections = await getLocalCollections(); - let uncategorizedCollection = collections.find( +export async function getUncategorizedCollection( + collections?: Collection[] +): Promise { + if (!collections) { + collections = await getLocalCollections(); + } + const uncategorizedCollection = collections.find( (collection) => collection.type === CollectionType.uncategorized ); - if (!uncategorizedCollection) { - uncategorizedCollection = await createUnCategorizedCollection(); - } + return uncategorizedCollection; } -async function createUnCategorizedCollection() { +export async function createUnCategorizedCollection() { return createCollection( UNCATEGORIZED_COLLECTION_NAME, CollectionType.uncategorized From f05446cb3343a5429de015acde73af1aac6a718d Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Thu, 2 Feb 2023 10:13:15 +0530 Subject: [PATCH 18/33] Changed width of menuOption --- src/components/OverflowMenu/option.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/OverflowMenu/option.tsx b/src/components/OverflowMenu/option.tsx index 9f0c49258..53dac8c8d 100644 --- a/src/components/OverflowMenu/option.tsx +++ b/src/components/OverflowMenu/option.tsx @@ -31,7 +31,7 @@ export function OverflowMenuOption({ theme.palette[color].main, padding: 1.5, '& .MuiSvgIcon-root': { From b505a3d3fa6784ee7d6e7b7a9d923590667434e3 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Thu, 2 Feb 2023 10:21:36 +0530 Subject: [PATCH 19/33] Changed Delete Album message and titles color --- src/components/Collections/CollectionOptions/index.tsx | 2 +- src/components/pages/gallery/SelectedFileOptions.tsx | 2 +- src/utils/strings/englishConstants.tsx | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/Collections/CollectionOptions/index.tsx b/src/components/Collections/CollectionOptions/index.tsx index 0b1104582..42241b4c7 100644 --- a/src/components/Collections/CollectionOptions/index.tsx +++ b/src/components/Collections/CollectionOptions/index.tsx @@ -197,7 +197,7 @@ const CollectionOptions = (props: CollectionOptionsProps) => { title: constants.DELETE_COLLECTION_TITLE, content: constants.DELETE_COLLECTION_MESSAGE(), proceed: { - text: constants.DELETE_COLLECTION, + text: constants.DELETE_PHOTOS, action: handleCollectionAction( CollectionActions.DELETE_WITH_FILES ), diff --git a/src/components/pages/gallery/SelectedFileOptions.tsx b/src/components/pages/gallery/SelectedFileOptions.tsx index b214ca35c..7e3f406ad 100644 --- a/src/components/pages/gallery/SelectedFileOptions.tsx +++ b/src/components/pages/gallery/SelectedFileOptions.tsx @@ -102,7 +102,7 @@ const SelectedFileOptions = ({ proceed: { action: removeFromCollectionHelper, text: constants.YES_REMOVE, - variant: 'danger', + variant: 'primary', }, close: { text: constants.CANCEL }, }); diff --git a/src/utils/strings/englishConstants.tsx b/src/utils/strings/englishConstants.tsx index cf9138447..b9460bd45 100644 --- a/src/utils/strings/englishConstants.tsx +++ b/src/utils/strings/englishConstants.tsx @@ -372,7 +372,8 @@ const englishConstants = { DELETE_COLLECTION_MESSAGE: () => (

Also delete the photos (and videos) present in this album from - all other albums they are part of? + all other albums they are + part of?

), DELETE_PHOTOS: 'Delete photos', @@ -607,7 +608,7 @@ const englishConstants = { ADD: 'Add', SORT: 'Sort', REMOVE: 'Remove', - YES_REMOVE: 'Yes, Remove', + YES_REMOVE: 'Yes, remove', CONFIRM_REMOVE: 'Confirm removal', REMOVE_FROM_COLLECTION: 'Remove from album', TRASH: 'Trash', From a4caacd3624b62dac69bafeb803a34f56dff851d Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Thu, 2 Feb 2023 10:37:04 +0530 Subject: [PATCH 20/33] Removed uncategorized collections from 'UPLOAD_NOT_ALLOWED_COLLECTION_TYPES' --- src/constants/collection/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/constants/collection/index.ts b/src/constants/collection/index.ts index 0d0b9eb88..d7d147fab 100644 --- a/src/constants/collection/index.ts +++ b/src/constants/collection/index.ts @@ -61,7 +61,6 @@ export const UPLOAD_NOT_ALLOWED_COLLECTION_TYPES = new Set([ CollectionSummaryType.archive, CollectionSummaryType.incomingShare, CollectionSummaryType.trash, - CollectionSummaryType.uncategorized, ]); export const OPTIONS_NOT_HAVING_COLLECTION_TYPES = new Set([ From afd7ef8907e643acf75e9e7c5c6720c848f3d076 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Thu, 2 Feb 2023 12:40:13 +0530 Subject: [PATCH 21/33] Added zero count option for sidebar section --- src/components/Sidebar/ShortcutButton.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/Sidebar/ShortcutButton.tsx b/src/components/Sidebar/ShortcutButton.tsx index fd1f1312f..ca9a46780 100644 --- a/src/components/Sidebar/ShortcutButton.tsx +++ b/src/components/Sidebar/ShortcutButton.tsx @@ -20,12 +20,11 @@ const ShortcutButton: FC> = ({ sx={{ fontWeight: 'normal' }} {...props}> {label} - {count > 0 && ( - - - {count} - - )} + + + + {count} + ); }; From 6c8ddb32bfa337d53336ce2295edac5d398a6dfa Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Thu, 2 Feb 2023 12:54:56 +0530 Subject: [PATCH 22/33] added uncategorized to 'UPLOAD_NOT_ALLOWED_COLLECTION_TYPE' --- src/constants/collection/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/constants/collection/index.ts b/src/constants/collection/index.ts index d7d147fab..0d0b9eb88 100644 --- a/src/constants/collection/index.ts +++ b/src/constants/collection/index.ts @@ -61,6 +61,7 @@ export const UPLOAD_NOT_ALLOWED_COLLECTION_TYPES = new Set([ CollectionSummaryType.archive, CollectionSummaryType.incomingShare, CollectionSummaryType.trash, + CollectionSummaryType.uncategorized, ]); export const OPTIONS_NOT_HAVING_COLLECTION_TYPES = new Set([ From 6d780f6b929e31ecdd8cbee1b6c6c5dc476599b1 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Thu, 2 Feb 2023 13:15:55 +0530 Subject: [PATCH 23/33] changed hasNonSystemCollections --- src/utils/collection/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utils/collection/index.ts b/src/utils/collection/index.ts index de2c63d38..e53bf381d 100644 --- a/src/utils/collection/index.ts +++ b/src/utils/collection/index.ts @@ -215,7 +215,10 @@ export const getArchivedCollections = (collections: Collection[]) => { export const hasNonSystemCollections = ( collectionSummaries: CollectionSummaries ) => { - return collectionSummaries?.size > 3; + for (const collectionSummary of collectionSummaries.values()) { + if (!isSystemCollection(collectionSummary.type)) return true; + } + return false; }; export const isUploadAllowedCollection = (type: CollectionSummaryType) => { From 16ff07f8e64ed6d329bcd2f91489cbfe033b2b7f Mon Sep 17 00:00:00 2001 From: Abhinav Date: Thu, 2 Feb 2023 13:23:22 +0530 Subject: [PATCH 24/33] show headers for non all section even if files count is zero --- src/components/PhotoFrame.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/PhotoFrame.tsx b/src/components/PhotoFrame.tsx index 3f243ce20..816594539 100644 --- a/src/components/PhotoFrame.tsx +++ b/src/components/PhotoFrame.tsx @@ -681,7 +681,10 @@ const PhotoFrame = ({ return ( <> - {!isFirstLoad && files.length === 0 && !isInSearchMode ? ( + {!isFirstLoad && + files.length === 0 && + !isInSearchMode && + activeCollection === ALL_SECTION ? ( ) : ( From ac2257771f5f5708461ed799c9a3ca7c48b3d54d Mon Sep 17 00:00:00 2001 From: Abhinav Date: Thu, 2 Feb 2023 20:52:28 +0530 Subject: [PATCH 25/33] optimize code --- src/services/collectionService.ts | 66 +++++++++++++++++++++---------- src/utils/file/index.ts | 12 ------ 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index f00e0c34a..73cc93235 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -12,7 +12,6 @@ import { isSharedFile, sortFiles, groupFilesBasedOnCollectionID, - groupFilesBasedOnID, } from 'utils/file'; import { Collection, @@ -496,31 +495,58 @@ const encryptWithNewCollectionKey = async ( }; export const removeFromCollection = async ( collectionID: number, - files: EnteFile[] + toRemoveFiles: EnteFile[] ) => { try { + const allFiles = await getLocalFiles(); + + const toRemoveFilesIds = new Set(toRemoveFiles.map((f) => f.id)); + const toRemoveFilesCopiesInOtherCollections = allFiles.filter((f) => { + if (f.collectionID === collectionID) { + return false; + } + return toRemoveFilesIds.has(f.id); + }); + const groupiedFiles = groupFilesBasedOnCollectionID( + toRemoveFilesCopiesInOtherCollections + ); + + const collections = await getLocalCollections(); + const collectionsMap = new Map(collections.map((c) => [c.id, c])); + + for (const [toMoveCollectionID, files] of groupiedFiles.entries()) { + const toMoveFiles = files.filter((f) => { + if (toRemoveFilesIds.has(f.id)) { + toRemoveFilesIds.delete(f.id); + return true; + } + return false; + }); + if (toMoveFiles.length === 0) { + continue; + } + await moveToCollection( + collectionsMap[toMoveCollectionID], + collectionID, + toMoveFiles + ); + } + const leftFiles = toRemoveFiles.filter((f) => + toRemoveFilesIds.has(f.id) + ); + + if (leftFiles.length === 0) { + return; + } let uncategorizedCollection = await getUncategorizedCollection(); if (!uncategorizedCollection) { uncategorizedCollection = await createUnCategorizedCollection(); } - const allFiles = await getLocalFiles(); - const groupiedFiles = groupFilesBasedOnID(allFiles); - for (const file of files) { - if (groupiedFiles[file.id].length === 1) { - await moveToCollection(uncategorizedCollection, collectionID, [ - file, - ]); - } else { - const differentCollectionFile = groupiedFiles[file.id].find( - (f) => f.collectionID !== collectionID - ); - const collections = await getLocalCollections(); - const collection = collections.find( - (c) => c.id === differentCollectionFile?.collectionID - ); - await moveToCollection(collection, collectionID, [file]); - } - } + await moveToCollection( + uncategorizedCollection, + collectionID, + leftFiles + ); } catch (e) { logError(e, 'remove from collection failed '); throw e; diff --git a/src/utils/file/index.ts b/src/utils/file/index.ts index f01efd297..e9b2be105 100644 --- a/src/utils/file/index.ts +++ b/src/utils/file/index.ts @@ -592,15 +592,3 @@ export const copyFileToClipboard = async (fileUrl: string) => { .write([new ClipboardItem({ 'image/png': blobPromise })]) .catch((e) => logError(e, 'failed to copy to clipboard')); }; - -export const groupFilesBasedOnID = (files: EnteFile[]) => { - const groupedFiles = files.reduce((acc, file) => { - if (!acc[file.id]) { - acc[file.id] = []; - } - acc[file.id].push(file); - return acc; - }, {} as { [key: number]: EnteFile[] }); - - return groupedFiles; -}; From aa427b7ac76df55483fe82e00de86ab0962f17fd Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Thu, 2 Feb 2023 21:15:29 +0530 Subject: [PATCH 26/33] Moved removeFromCollection logic from collectionOptions to collectionServices --- src/components/Collections/CollectionOptions/index.tsx | 9 --------- src/services/collectionService.ts | 7 +++++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/components/Collections/CollectionOptions/index.tsx b/src/components/Collections/CollectionOptions/index.tsx index 42241b4c7..a239e27db 100644 --- a/src/components/Collections/CollectionOptions/index.tsx +++ b/src/components/Collections/CollectionOptions/index.tsx @@ -22,7 +22,6 @@ import { OnlyDownloadCollectionOption } from './OnlyDownloadCollectionOption'; import { QuickOptions } from './QuickOptions'; import MoreHoriz from '@mui/icons-material/MoreHoriz'; import { HorizontalFlex } from 'components/Container'; -import { getLocalFiles } from 'services/fileService'; interface CollectionOptionsProps { setCollectionNamerAttributes: SetCollectionNamerAttributes; @@ -148,14 +147,6 @@ const CollectionOptions = (props: CollectionOptionsProps) => { }; const deleteCollectionButKeepFiles = async () => { - const allFiles = await getLocalFiles(); - const collectionFiles = allFiles.filter((file) => { - return file.collectionID === activeCollection.id; - }); - await CollectionAPI.removeFromCollection( - activeCollection.id, - collectionFiles - ); await CollectionAPI.deleteCollection(activeCollection.id, true); redirectToAll(); }; diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index f00e0c34a..d9c3c9bc2 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -532,6 +532,13 @@ export const deleteCollection = async ( keepFiles: boolean ) => { try { + if (keepFiles) { + const allFiles = await getLocalFiles(); + const collectionFiles = allFiles.filter((file) => { + return file.collectionID === collectionID; + }); + await removeFromCollection(collectionID, collectionFiles); + } const token = getToken(); await HTTPService.delete( From d9acaef3b8f7c77ceb7f502ee7a0130445b83207 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Thu, 2 Feb 2023 22:12:42 +0530 Subject: [PATCH 27/33] changed how we check isUncategorizedCollection prop in SelectedFileOptions of gallery --- src/pages/gallery/index.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 5ae4445fe..f33de7d14 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -60,6 +60,7 @@ import Uploader from 'components/Upload/Uploader'; import { ALL_SECTION, ARCHIVE_SECTION, + CollectionSummaryType, CollectionType, DUMMY_UNCATEGORIZED_SECTION, TRASH_SECTION, @@ -74,7 +75,6 @@ import { handleCollectionOps, getSelectedCollection, isFavoriteCollection, - isUncategorizedCollection, getArchivedCollections, hasNonSystemCollections, } from 'utils/collection'; @@ -782,10 +782,10 @@ export default function Gallery() { activeCollection, collections )} - isUncategorizedCollection={isUncategorizedCollection( - activeCollection, - collections - )} + isUncategorizedCollection={ + collectionSummaries[activeCollection] === + CollectionSummaryType.uncategorized + } /> )} From 03b3b433186c1cd95c484c9fe876cfbcfaf78c3c Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Thu, 2 Feb 2023 22:23:41 +0530 Subject: [PATCH 28/33] changed how we check isFavoriteCollection and isSharedCollection prop in SelectedFileOptions of gallery --- src/pages/gallery/index.tsx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index f33de7d14..b8c588544 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -71,10 +71,8 @@ import { CustomError, ServerErrorCodes } from 'utils/error'; import { PAGES } from 'constants/pages'; import { COLLECTION_OPS_TYPE, - isSharedCollection, handleCollectionOps, getSelectedCollection, - isFavoriteCollection, getArchivedCollections, hasNonSystemCollections, } from 'utils/collection'; @@ -729,10 +727,10 @@ export default function Gallery() { deletedFileIds={deletedFileIds} setDeletedFileIds={setDeletedFileIds} activeCollection={activeCollection} - isSharedCollection={isSharedCollection( - activeCollection, - collections - )} + isSharedCollection={ + collectionSummaries[activeCollection] === + CollectionSummaryType.incomingShare + } enableDownload={true} resetSearch={resetSearch} /> @@ -778,10 +776,10 @@ export default function Gallery() { count={selected.count} clearSelection={clearSelection} activeCollection={activeCollection} - isFavoriteCollection={isFavoriteCollection( - activeCollection, - collections - )} + isFavoriteCollection={ + collectionSummaries[activeCollection] === + CollectionSummaryType.favorites + } isUncategorizedCollection={ collectionSummaries[activeCollection] === CollectionSummaryType.uncategorized From 98e3186d447becd7f82802392f4b32d19096f240 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Thu, 2 Feb 2023 22:33:53 +0530 Subject: [PATCH 29/33] Added allFiles parameter in removeFromCollection api of Collection Servies --- src/services/collectionService.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index 227f8cfc2..408023f85 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -495,10 +495,13 @@ const encryptWithNewCollectionKey = async ( }; export const removeFromCollection = async ( collectionID: number, - toRemoveFiles: EnteFile[] + toRemoveFiles: EnteFile[], + allFiles?: EnteFile[] ) => { try { - const allFiles = await getLocalFiles(); + if (!allFiles) { + allFiles = await getLocalFiles(); + } const toRemoveFilesIds = new Set(toRemoveFiles.map((f) => f.id)); const toRemoveFilesCopiesInOtherCollections = allFiles.filter((f) => { @@ -563,7 +566,7 @@ export const deleteCollection = async ( const collectionFiles = allFiles.filter((file) => { return file.collectionID === collectionID; }); - await removeFromCollection(collectionID, collectionFiles); + await removeFromCollection(collectionID, collectionFiles, allFiles); } const token = getToken(); From f9b46e11d777f7c13fa89f3f2381dbde9ccb0611 Mon Sep 17 00:00:00 2001 From: Ananddubey01 Date: Thu, 2 Feb 2023 22:49:27 +0530 Subject: [PATCH 30/33] Changed isSharedCollection check name to isIncomingSharedCollection --- src/components/PhotoFrame.tsx | 13 ++++++++----- src/components/PhotoViewer/index.tsx | 16 ++++++++++------ src/pages/gallery/index.tsx | 2 +- src/pages/shared-albums/index.tsx | 2 +- src/types/collection/index.ts | 2 +- src/utils/collection/index.ts | 2 +- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/components/PhotoFrame.tsx b/src/components/PhotoFrame.tsx index 816594539..e549733ae 100644 --- a/src/components/PhotoFrame.tsx +++ b/src/components/PhotoFrame.tsx @@ -66,7 +66,7 @@ interface Props { deletedFileIds?: Set; setDeletedFileIds?: (value: Set) => void; activeCollection: number; - isSharedCollection?: boolean; + isIncomingSharedCollection?: boolean; enableDownload?: boolean; isDeduplicating?: boolean; resetSearch?: () => void; @@ -95,7 +95,7 @@ const PhotoFrame = ({ deletedFileIds, setDeletedFileIds, activeCollection, - isSharedCollection, + isIncomingSharedCollection, enableDownload, isDeduplicating, }: Props) => { @@ -179,7 +179,10 @@ const PhotoFrame = ({ return false; } - if (isSharedFile(user, item) && !isSharedCollection) { + if ( + isSharedFile(user, item) && + !isIncomingSharedCollection + ) { return false; } if (activeCollection === TRASH_SECTION && !item.isTrashed) { @@ -499,7 +502,7 @@ const PhotoFrame = ({ file={files[index]} updateURL={updateURL(files[index].id)} onClick={onThumbnailClick(index)} - selectable={!isSharedCollection} + selectable={!isIncomingSharedCollection} onSelect={handleSelect(files[index].id, index)} selected={ selected.collectionID === activeCollection && @@ -714,7 +717,7 @@ const PhotoFrame = ({ favItemIds={favItemIds} deletedFileIds={deletedFileIds} setDeletedFileIds={setDeletedFileIds} - isSharedCollection={isSharedCollection} + isIncomingSharedCollection={isIncomingSharedCollection} isTrashCollection={activeCollection === TRASH_SECTION} enableDownload={enableDownload} isSourceLoaded={isSourceLoaded} diff --git a/src/components/PhotoViewer/index.tsx b/src/components/PhotoViewer/index.tsx index bd5ba104f..872716085 100644 --- a/src/components/PhotoViewer/index.tsx +++ b/src/components/PhotoViewer/index.tsx @@ -68,7 +68,7 @@ interface Iprops { favItemIds: Set; deletedFileIds: Set; setDeletedFileIds?: (value: Set) => void; - isSharedCollection: boolean; + isIncomingSharedCollection: boolean; isTrashCollection: boolean; enableDownload: boolean; isSourceLoaded: boolean; @@ -393,7 +393,11 @@ function PhotoViewer(props: Iprops) { }; const confirmTrashFile = (file: EnteFile) => { - if (!file || props.isSharedCollection || props.isTrashCollection) { + if ( + !file || + props.isIncomingSharedCollection || + props.isTrashCollection + ) { return; } appContext.setDialogMessage(getTrashFileMessage(() => trashFile(file))); @@ -571,7 +575,7 @@ function PhotoViewer(props: Iprops) { )} - {!props.isSharedCollection && + {!props.isIncomingSharedCollection && !props.isTrashCollection && ( )} - {!props.isSharedCollection && + {!props.isIncomingSharedCollection && !props.isTrashCollection && (