diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 26d013b9d..a438463d9 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -19,7 +19,6 @@ import { syncCollections, getFavItemIds, getLocalCollections, - getNonEmptyCollections, createCollection, getCollectionSummaries, } from 'services/collectionService'; @@ -371,13 +370,11 @@ export default function Gallery() { } const favItemIds = await getFavItemIds(files); setFavItemIds(favItemIds); - const nonEmptyCollections = getNonEmptyCollections(collections, files); - - const archivedCollections = getArchivedCollections(nonEmptyCollections); + const archivedCollections = getArchivedCollections(collections); setArchivedCollections(archivedCollections); const collectionSummaries = getCollectionSummaries( - nonEmptyCollections, + collections, files, archivedCollections ); diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index c2eff39ac..1b738263b 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -714,7 +714,9 @@ export const getNonEmptyCollections = ( ) => { const nonEmptyCollectionsIds = new Set(); for (const file of files) { - nonEmptyCollectionsIds.add(file.collectionID); + if (!file.isTrashed) { + nonEmptyCollectionsIds.add(file.collectionID); + } } return collections.filter((collection) => nonEmptyCollectionsIds.has(collection.id) @@ -810,7 +812,8 @@ export function getCollectionSummaries( collectionLatestFiles ) ); - return collectionSummaries; + + return filterOutEmptyCollectionSummary(collectionSummaries); } function getCollectionsFileCount(files: EnteFile[]): CollectionFilesCount { @@ -882,3 +885,12 @@ function getTrashedCollectionSummaries( updationTime: collectionsLatestFile.get(TRASH_SECTION)?.updationTime, }; } + +function filterOutEmptyCollectionSummary( + collectionSummaries: CollectionSummaries +) { + return new Map( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + [...collectionSummaries.entries()].filter(([_, v]) => v.fileCount > 0) + ) as CollectionSummaries; +} diff --git a/src/utils/file/index.ts b/src/utils/file/index.ts index 3bb4bccfa..41fa54342 100644 --- a/src/utils/file/index.ts +++ b/src/utils/file/index.ts @@ -147,13 +147,13 @@ export function sortFilesIntoCollections(files: EnteFile[]) { if (!collectionWiseFiles.has(file.collectionID)) { collectionWiseFiles.set(file.collectionID, []); } - - collectionWiseFiles.get(file.collectionID).push(file); - if (IsArchived(file)) { - collectionWiseFiles.get(ARCHIVE_SECTION).push(file); - } if (file.isTrashed) { collectionWiseFiles.get(TRASH_SECTION).push(file); + } else { + collectionWiseFiles.get(file.collectionID).push(file); + if (IsArchived(file)) { + collectionWiseFiles.get(ARCHIVE_SECTION).push(file); + } } } return collectionWiseFiles;