π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Improve
Manav Rathi2d0e2000c230
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.tsindex 9fc069b901..d7a72f111f 100644--- a/web/apps/photos/src/services/collectionService.ts+++ b/web/apps/photos/src/services/collectionService.ts@@ -1013,7 +1013,10 @@ export const sortCollectionSummaries = (CollectionSummaryOrder.get(b.type),);-function compareCollectionsLatestFile(first: EnteFile, second: EnteFile) {+function compareCollectionsLatestFile(+ first: EnteFile | undefined,+ second: EnteFile | undefined,+) {if (!first) {return 1;} else if (!second) {diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.tsindex c6507a3750..3c6a13d017 100644--- a/web/packages/new/photos/components/gallery/reducer.ts+++ b/web/packages/new/photos/components/gallery/reducer.ts@@ -75,14 +75,20 @@ export interface GalleryState {hiddenCollections: Collection[];/*** The user's normal (non-hidden, non-trash) files.+ *+ * The list is sorted so that the newest file is first.*/files: EnteFile[];/*** The user's hidden files.+ *+ * The list is sorted so that the newest file is first.*/hiddenFiles: EnteFile[];/*** The user's files that are in Trash.+ *+ * The list is sorted so that the newest file is first.*/trashedFiles: EnteFile[];@@ -411,8 +417,8 @@ export const useGalleryReducer = () =>* have two "Collection File" entries for it, both with the same file ID, but* with different collection IDs.*- * This function returns files such that only one of these entries (arbitrarily- * picked in case of dupes) is returned.+ * This function returns files such that only one of these entries (the newer+ * one in case of dupes) is returned.*/export const uniqueFilesByID = (files: EnteFile[]) => {const seen = new Set<number>();@@ -522,8 +528,12 @@ const createCollectionSummaries = (files: EnteFile[],) => {const collectionSummaries = new Map<number, CollectionSummary>();- const collectionLatestFiles = getCollectionLatestFiles(files);- const collectionCoverFiles = getCollectionCoverFiles(files, collections);++ const filesByCollection = groupFilesByCollectionID(files);+ const collectionCoverFiles = getCollectionCoverFiles(+ collections,+ filesByCollection,+ );const collectionFilesCount = getCollectionsFileCount(files);let hasUncategorizedCollection = false;@@ -583,11 +593,7 @@ const createCollectionSummaries = (collectionSummaries.set(collection.id, {id: collection.id,name: CollectionSummaryItemName,- // See: [Note: strict mode migration]- //- // eslint-disable-next-line @typescript-eslint/ban-ts-comment- // @ts-ignore- latestFile: collectionLatestFiles.get(collection.id),+ latestFile: filesByCollection.get(collection.id)?.[0],coverFile: collectionCoverFiles.get(collection.id),fileCount: collectionFilesCount.get(collection.id) ?? 0,updationTime: collection.updationTime,@@ -607,30 +613,14 @@ const createCollectionSummaries = (return collectionSummaries;};-type CollectionToFileMap = Map<number, EnteFile>;--// TODO: This seems to rely on some sort order. Document.-const getCollectionLatestFiles = (files: EnteFile[]): CollectionToFileMap => {- const latestFiles = new Map<number, EnteFile>();-- files.forEach((file) => {- if (!latestFiles.has(file.collectionID)) {- latestFiles.set(file.collectionID, file);- }- });- return latestFiles;-};-const getCollectionCoverFiles = (- files: EnteFile[],collections: Collection[],-): CollectionToFileMap => {- const collectionIDToFileMap = groupFilesByCollectionID(files);-+ filesByCollection: Map<number, EnteFile[]>,+): Map<number, EnteFile> => {const coverFiles = new Map<number, EnteFile>();collections.forEach((collection) => {- const collectionFiles = collectionIDToFileMap.get(collection.id);+ const collectionFiles = filesByCollection.get(collection.id);if (!collectionFiles || collectionFiles.length === 0) {return;}@@ -688,11 +678,7 @@ function getDummyUncategorizedCollectionSummary(): CollectionSummary {id: DUMMY_UNCATEGORIZED_COLLECTION,name: t("section_uncategorized"),type: "uncategorized",- // See: [Note: strict mode migration]- //- // eslint-disable-next-line @typescript-eslint/ban-ts-comment- // @ts-ignore- latestFile: null,+ latestFile: undefined,// See: [Note: strict mode migration]//// eslint-disable-next-line @typescript-eslint/ban-ts-commentdiff --git a/web/packages/new/photos/services/collection/ui.ts b/web/packages/new/photos/services/collection/ui.tsindex 50dcb5b3f5..ad1841cc73 100644--- a/web/packages/new/photos/services/collection/ui.ts+++ b/web/packages/new/photos/services/collection/ui.ts@@ -22,12 +22,32 @@ export type CollectionSummaryType =* directly shown in the UI.*/export interface CollectionSummary {- /** The "UI" type for the collection. */+ /**+ * The "UI" type for the collection or pseudo-collection.+ */type: CollectionSummaryType;+ /**+ * The ID of the underlying collection, or one of the predefined placeholder+ * IDs for the pseudo-collections.+ */id: number;+ /**+ * The name of the collection or pseudo-collection.+ */name: string;+ /**+ * The newest file in the collection or pseudo-collection (if it is not+ * empty).+ */+ latestFile: EnteFile | undefined;+ /**+ * The file to show as the cover for the collection or pseudo-collection.+ */coverFile: EnteFile | undefined;- latestFile: EnteFile;+ /**+ * The number of files in the underlying collection, or the number of files+ * that belong to this pseudo-collection.+ */fileCount: number;updationTime: number;order?: number;