diff --git a/src/components/Collections/AllCollections/index.tsx b/src/components/Collections/AllCollections/index.tsx index cbcfd2d31..c0e0910d4 100644 --- a/src/components/Collections/AllCollections/index.tsx +++ b/src/components/Collections/AllCollections/index.tsx @@ -1,6 +1,9 @@ import React, { useMemo } from 'react'; import Divider from '@mui/material/Divider'; -import { CollectionType, COLLECTION_SORT_BY } from 'constants/collection'; +import { + COLLECTION_SORT_BY, + SPECIAL_COLLECTION_TYPES, +} from 'constants/collection'; import { sortCollectionSummaries } from 'services/collectionService'; import { Transition, @@ -35,7 +38,7 @@ export default function AllCollections(props: Iprops) { () => sortCollectionSummaries( [...collectionSummaries.values()].filter( - (x) => x.type !== CollectionType.system + (x) => !SPECIAL_COLLECTION_TYPES.has(x.type) ), collectionSortBy ), diff --git a/src/components/Collections/CollectionBar/index.tsx b/src/components/Collections/CollectionBar/index.tsx index 5ec6fb772..ac4736545 100644 --- a/src/components/Collections/CollectionBar/index.tsx +++ b/src/components/Collections/CollectionBar/index.tsx @@ -96,13 +96,6 @@ export default function CollectionBar(props: IProps) { /> )} - - {sortedCollectionSummary.map((item) => ( - {type !== CollectionType.system && - type !== CollectionType.favorites && ( - - )} + {!SPECIAL_COLLECTION_TYPES.has(type) && ( + + )} ); diff --git a/src/components/pages/gallery/CollectionSelector.tsx b/src/components/pages/gallery/CollectionSelector.tsx index 5aa4c4f8b..a17033209 100644 --- a/src/components/pages/gallery/CollectionSelector.tsx +++ b/src/components/pages/gallery/CollectionSelector.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useMemo } from 'react'; import AddCollectionButton from './AddCollectionButton'; import { Collection, CollectionSummaries } from 'types/collection'; -import { CollectionType } from 'constants/collection'; +import { SPECIAL_COLLECTION_TYPES } from 'constants/collection'; import DialogBoxBase from 'components/DialogBox/base'; import DialogTitleWithCloseButton from 'components/DialogBox/titleWithCloseButton'; import { DialogContent } from '@mui/material'; @@ -36,11 +36,9 @@ function CollectionSelector({ const personalCollectionsOtherThanFrom = [ ...collectionSummaries.values(), ]?.filter( - ({ type, id, isSharedAlbum }) => + ({ type, id }) => id !== attributes?.fromCollection && - !isSharedAlbum && - type !== CollectionType.favorites && - type !== CollectionType.system + !SPECIAL_COLLECTION_TYPES.has(type) ); return personalCollectionsOtherThanFrom; }, [collectionSummaries, attributes]); diff --git a/src/constants/collection/index.ts b/src/constants/collection/index.ts index b8d87074e..389934138 100644 --- a/src/constants/collection/index.ts +++ b/src/constants/collection/index.ts @@ -6,7 +6,10 @@ export enum CollectionType { folder = 'folder', favorites = 'favorites', album = 'album', - system = 'system', + archive = 'archive', + trash = 'trash', + all = 'all', + shared = 'shared', } export enum COLLECTION_SORT_BY { @@ -19,3 +22,20 @@ export enum COLLECTION_SORT_BY { export const COLLECTION_SHARE_DEFAULT_VALID_DURATION = 10 * 24 * 60 * 60 * 1000 * 1000; export const COLLECTION_SHARE_DEFAULT_DEVICE_LIMIT = 4; + +export const COLLECTION_SORT_ORDER = new Map([ + [CollectionType.all, 0], + [CollectionType.favorites, 1], + [CollectionType.album, 2], + [CollectionType.folder, 2], + [CollectionType.shared, 2], + [CollectionType.archive, 3], + [CollectionType.trash, 4], +]); + +export const SPECIAL_COLLECTION_TYPES = new Set([ + CollectionType.all, + CollectionType.archive, + CollectionType.trash, + CollectionType.shared, +]); diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index 4ba345afc..575b2f84f 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -30,6 +30,8 @@ import { CollectionType, ARCHIVE_SECTION, TRASH_SECTION, + COLLECTION_SORT_ORDER, + ALL_SECTION, } from 'constants/collection'; import { UpdateMagicMetadataRequest } from 'types/magicMetadata'; import { EncryptionResult } from 'types/upload'; @@ -714,8 +716,8 @@ export function sortCollectionSummaries( collectionSummaries: CollectionSummary[], sortBy: COLLECTION_SORT_BY ) { - return moveFavCollectionToFront( - collectionSummaries.sort((a, b) => { + return collectionSummaries + .sort((a, b) => { switch (sortBy) { case COLLECTION_SORT_BY.CREATION_TIME_DESCENDING: return compareCollectionsLatestFile( @@ -733,7 +735,11 @@ export function sortCollectionSummaries( return a.name.localeCompare(b.name); } }) - ); + .sort( + (a, b) => + COLLECTION_SORT_ORDER.get(a.type) - + COLLECTION_SORT_ORDER.get(b.type) + ); } function compareCollectionsLatestFile(first: EnteFile, second: EnteFile) { @@ -745,16 +751,6 @@ function compareCollectionsLatestFile(first: EnteFile, second: EnteFile) { } } -function moveFavCollectionToFront(collectionSummaries: CollectionSummary[]) { - return collectionSummaries.sort((a, b) => - a.type === CollectionType.favorites - ? -1 - : b.type === CollectionType.favorites - ? 1 - : 0 - ); -} - export function getCollectionSummaries( collections: Collection[], files: EnteFile[] @@ -768,13 +764,19 @@ export function getCollectionSummaries( collectionSummaries.set(collection.id, { id: collection.id, name: collection.name, - type: collection.type, latestFile: collectionLatestFiles.get(collection.id), fileCount: collectionFilesCount.get(collection.id) ?? 0, updationTime: collection.updationTime, - isSharedAlbum: collection.owner.id !== user.id, + type: + collection.owner.id !== user.id + ? CollectionType.shared + : collection.type, }); } + collectionSummaries.set( + ALL_SECTION, + getAllCollectionSummaries(files.length, files[0]) + ); collectionSummaries.set( ARCHIVE_SECTION, getArchivedCollectionSummaries( @@ -801,18 +803,31 @@ function getCollectionsFileCount(files: EnteFile[]): CollectionFilesCount { return collectionFilesCount; } +function getAllCollectionSummaries( + allFilesCount: number, + latestFile: EnteFile +): CollectionSummary { + return { + id: ALL_SECTION, + name: constants.ALL_SECTION_NAME, + type: CollectionType.all, + latestFile: latestFile, + fileCount: allFilesCount, + updationTime: latestFile?.updationTime, + }; +} + function getArchivedCollectionSummaries( collectionFilesCount: CollectionFilesCount, collectionsLatestFile: CollectionLatestFiles ): CollectionSummary { return { id: ARCHIVE_SECTION, - name: constants.ARCHIVED, - type: CollectionType.system, + name: constants.ARCHIVE_SECTION_NAME, + type: CollectionType.archive, latestFile: collectionsLatestFile.get(ARCHIVE_SECTION), fileCount: collectionFilesCount.get(ARCHIVE_SECTION) ?? 0, updationTime: collectionsLatestFile.get(ARCHIVE_SECTION)?.updationTime, - isSharedAlbum: false, }; } @@ -823,10 +838,9 @@ function getTrashedCollectionSummaries( return { id: TRASH_SECTION, name: constants.TRASH, - type: CollectionType.system, + type: CollectionType.trash, latestFile: collectionsLatestFile.get(TRASH_SECTION), fileCount: collectionFilesCount.get(TRASH_SECTION) ?? 0, updationTime: collectionsLatestFile.get(TRASH_SECTION)?.updationTime, - isSharedAlbum: false, }; } diff --git a/src/types/collection/index.ts b/src/types/collection/index.ts index 795e1cfff..5860a4641 100644 --- a/src/types/collection/index.ts +++ b/src/types/collection/index.ts @@ -95,7 +95,6 @@ export interface CollectionSummary { latestFile: EnteFile; fileCount: number; updationTime: number; - isSharedAlbum: boolean; } export type CollectionSummaries = Map; diff --git a/src/utils/strings/englishConstants.tsx b/src/utils/strings/englishConstants.tsx index a0b7c8610..479260012 100644 --- a/src/utils/strings/englishConstants.tsx +++ b/src/utils/strings/englishConstants.tsx @@ -582,8 +582,8 @@ const englishConstants = { 'These files were uploaded, but unfortunately we could not generate the thumbnails for them.', UPLOAD_TO_COLLECTION: 'Upload to album', ARCHIVE: 'Hide', - ARCHIVED: 'Hidden', - ALL_SECTION_NAME: 'All Photos', + ARCHIVE_SECTION_NAME: 'Hidden', + ALL_SECTION_NAME: 'All memories', MOVE_TO_COLLECTION: 'Move to album', UNARCHIVE: 'Unhide', MOVE: 'Move',