From 9f92787ac613cb27e76035d6515e3c41b6b25951 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 17 Sep 2024 14:27:46 +0530 Subject: [PATCH] [web] Show empty albums also Matches the behaviour on mobile. --- .../photos/src/services/collectionService.ts | 92 ++++++++----------- web/apps/photos/src/services/export/index.ts | 16 ++-- .../photos/src/services/export/migration.ts | 9 +- web/apps/photos/src/utils/collection.ts | 19 ---- web/apps/photos/tests/upload.test.ts | 11 +-- 5 files changed, 48 insertions(+), 99 deletions(-) diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts index 80f7f741b4..483719ea8c 100644 --- a/web/apps/photos/src/services/collectionService.ts +++ b/web/apps/photos/src/services/collectionService.ts @@ -1069,19 +1069,6 @@ export const getFavCollection = async () => { } }; -export const getNonEmptyCollections = ( - collections: Collection[], - files: EnteFile[], -) => { - const nonEmptyCollectionsIds = new Set(); - for (const file of files) { - nonEmptyCollectionsIds.add(file.collectionID); - } - return collections.filter((collection) => - nonEmptyCollectionsIds.has(collection.id), - ); -}; - export function sortCollectionSummaries( collectionSummaries: CollectionSummary[], sortBy: COLLECTION_LIST_SORT_BY, @@ -1141,51 +1128,46 @@ export function getCollectionSummaries( ) { hasUncategorizedCollection = true; } - if ( - collectionFilesCount.get(collection.id) || - collection.type === CollectionType.uncategorized - ) { - let type: CollectionSummaryType; - if (isIncomingShare(collection, user)) { - if (isIncomingCollabShare(collection, user)) { - type = CollectionSummaryType.incomingShareCollaborator; - } else { - type = CollectionSummaryType.incomingShareViewer; - } - } else if (isOutgoingShare(collection, user)) { - type = CollectionSummaryType.outgoingShare; - } else if (isSharedOnlyViaLink(collection)) { - type = CollectionSummaryType.sharedOnlyViaLink; - } else if (isArchivedCollection(collection)) { - type = CollectionSummaryType.archived; - } else if (isDefaultHiddenCollection(collection)) { - type = CollectionSummaryType.defaultHidden; - } else if (isPinnedCollection(collection)) { - type = CollectionSummaryType.pinned; + let type: CollectionSummaryType; + if (isIncomingShare(collection, user)) { + if (isIncomingCollabShare(collection, user)) { + type = CollectionSummaryType.incomingShareCollaborator; } else { - type = CollectionSummaryType[collection.type]; + type = CollectionSummaryType.incomingShareViewer; } - - let CollectionSummaryItemName: string; - if (type === CollectionSummaryType.uncategorized) { - CollectionSummaryItemName = t("UNCATEGORIZED"); - } else if (type === CollectionSummaryType.favorites) { - CollectionSummaryItemName = t("FAVORITES"); - } else { - CollectionSummaryItemName = collection.name; - } - - collectionSummaries.set(collection.id, { - id: collection.id, - name: CollectionSummaryItemName, - latestFile: collectionLatestFiles.get(collection.id), - coverFile: collectionCoverFiles.get(collection.id), - fileCount: collectionFilesCount.get(collection.id) ?? 0, - updationTime: collection.updationTime, - type: type, - order: collection.magicMetadata?.data?.order ?? 0, - }); + } else if (isOutgoingShare(collection, user)) { + type = CollectionSummaryType.outgoingShare; + } else if (isSharedOnlyViaLink(collection)) { + type = CollectionSummaryType.sharedOnlyViaLink; + } else if (isArchivedCollection(collection)) { + type = CollectionSummaryType.archived; + } else if (isDefaultHiddenCollection(collection)) { + type = CollectionSummaryType.defaultHidden; + } else if (isPinnedCollection(collection)) { + type = CollectionSummaryType.pinned; + } else { + type = CollectionSummaryType[collection.type]; } + + let CollectionSummaryItemName: string; + if (type === CollectionSummaryType.uncategorized) { + CollectionSummaryItemName = t("UNCATEGORIZED"); + } else if (type === CollectionSummaryType.favorites) { + CollectionSummaryItemName = t("FAVORITES"); + } else { + CollectionSummaryItemName = collection.name; + } + + collectionSummaries.set(collection.id, { + id: collection.id, + name: CollectionSummaryItemName, + latestFile: collectionLatestFiles.get(collection.id), + coverFile: collectionCoverFiles.get(collection.id), + fileCount: collectionFilesCount.get(collection.id) ?? 0, + updationTime: collection.updationTime, + type: type, + order: collection.magicMetadata?.data?.order ?? 0, + }); } if (!hasUncategorizedCollection) { collectionSummaries.set( diff --git a/web/apps/photos/src/services/export/index.ts b/web/apps/photos/src/services/export/index.ts index a130f9f729..5e53b99a18 100644 --- a/web/apps/photos/src/services/export/index.ts +++ b/web/apps/photos/src/services/export/index.ts @@ -39,7 +39,6 @@ import { import { constructCollectionNameMap, getCollectionUserFacingName, - getNonEmptyPersonalCollections, } from "utils/collection"; import { getPersonalFiles } from "utils/file"; import { getAllLocalCollections } from "../collectionService"; @@ -354,10 +353,8 @@ class ExportService { collectionIdToOwnerIDMap, ); - const nonEmptyPersonalCollections = getNonEmptyPersonalCollections( - collections, - personalFiles, - user, + const personalCollections = collections.filter( + (collection) => collection.owner.id === user?.id, ); const exportRecord = await this.getExportRecord(exportFolder); @@ -365,12 +362,11 @@ class ExportService { convertCollectionIDExportNameObjectToMap( exportRecord.collectionExportNames, ); - const collectionIDNameMap = constructCollectionNameMap( - nonEmptyPersonalCollections, - ); + const collectionIDNameMap = + constructCollectionNameMap(personalCollections); const renamedCollections = getRenamedExportedCollections( - nonEmptyPersonalCollections, + personalCollections, exportRecord, ); @@ -396,7 +392,7 @@ class ExportService { ); const deletedExportedCollections = getDeletedExportedCollections( - nonEmptyPersonalCollections, + personalCollections, exportRecord, ); diff --git a/web/apps/photos/src/services/export/migration.ts b/web/apps/photos/src/services/export/migration.ts index 2116ca258c..9727bbe883 100644 --- a/web/apps/photos/src/services/export/migration.ts +++ b/web/apps/photos/src/services/export/migration.ts @@ -28,7 +28,6 @@ import { ExportedCollectionPaths, FileExportNames, } from "types/export"; -import { getNonEmptyPersonalCollections } from "utils/collection"; import { getIDBasedSortedFiles, getPersonalFiles } from "utils/file"; import { getCollectionIDFromFileUID, @@ -111,13 +110,11 @@ async function migrationV0ToV1( const personalFiles = getIDBasedSortedFiles( getPersonalFiles(localFiles, user), ); - const nonEmptyPersonalCollections = getNonEmptyPersonalCollections( - localCollections, - personalFiles, - user, + const personalCollections = localCollections.filter( + (collection) => collection.owner.id === user?.id, ); await migrateCollectionFolders( - nonEmptyPersonalCollections, + personalCollections, exportDir, collectionIDPathMap, ); diff --git a/web/apps/photos/src/utils/collection.ts b/web/apps/photos/src/utils/collection.ts index 084bbc97ea..a85e36e677 100644 --- a/web/apps/photos/src/utils/collection.ts +++ b/web/apps/photos/src/utils/collection.ts @@ -23,7 +23,6 @@ import { createAlbum, getAllLocalCollections, getLocalCollections, - getNonEmptyCollections, moveToCollection, removeFromCollection, restoreToCollection, @@ -546,24 +545,6 @@ export function getCollectionNameMap( ); } -export function getNonEmptyPersonalCollections( - collections: Collection[], - personalFiles: EnteFile[], - user: User, -): Collection[] { - if (!user?.id) { - throw Error("user missing"); - } - const nonEmptyCollections = getNonEmptyCollections( - collections, - personalFiles, - ); - const personalCollections = nonEmptyCollections.filter( - (collection) => collection.owner.id === user?.id, - ); - return personalCollections; -} - export function getNonHiddenCollections( collections: Collection[], ): Collection[] { diff --git a/web/apps/photos/tests/upload.test.ts b/web/apps/photos/tests/upload.test.ts index faa485d383..7dd604b0ae 100644 --- a/web/apps/photos/tests/upload.test.ts +++ b/web/apps/photos/tests/upload.test.ts @@ -140,19 +140,12 @@ async function totalFileCountCheck(expectedState) { async function totalCollectionCountCheck(expectedState) { const collections = await getLocalCollections(); - const files = await getLocalFiles(); - const nonEmptyCollectionIds = new Set( - files.map((file) => file.collectionID), - ); - const nonEmptyCollections = collections.filter((collection) => - nonEmptyCollectionIds.has(collection.id), - ); - if (expectedState["collection_count"] === nonEmptyCollections.length) { + if (expectedState["collection_count"] === collections.length) { console.log("collection count check passed ✅"); } else { throw Error( `total Collection count check failed ❌ - expected : ${expectedState["collection_count"]}, got: ${nonEmptyCollections.length}`, + expected : ${expectedState["collection_count"]}, got: ${collections.length}`, ); } }