From 66079b0af295d24ee9b1e5dbbd5b2aa127032877 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Wed, 25 Jun 2025 10:59:47 +0530 Subject: [PATCH] Outline --- .../new/photos/components/gallery/reducer.ts | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts index 68c0bd23a6..4309c7c176 100644 --- a/web/packages/new/photos/components/gallery/reducer.ts +++ b/web/packages/new/photos/components/gallery/reducer.ts @@ -125,6 +125,15 @@ export interface GalleryState { * The user's hidden collections. */ hiddenCollections: Collection[]; + /** + * The user's files, without any unsynced modifications applied to them. + * + * The list is sorted so that newer files are first. + * + * This property is expected to be of use only internal to the reducer; + * external code should only needs {@link files} instead. + */ + lastSyncedFiles: EnteFile[]; /** * The user's normal (non-hidden, non-trash) files, without any unsynced * modifications applied to them. @@ -161,11 +170,18 @@ export interface GalleryState { /*--< Derived state >--*/ /** - * The user's normal (non-hidden, non-trash) files, with any unsynced - * modifications also applied to them. + * The user's "collection files", with any unsynced modifications also + * applied to them. + * + * "Collection files" means that there might be multiple entries for the + * same file ID, one for each collection the file belongs to. For more + * details, see [Note: Collection file]. * * The list is sorted so that newer files are first. * + * See {@link lastSyncedFiles} for the same list, but without unsynced + * modifications. + * * [Note: Unsynced modifications] * * Unsynced modifications are those whose effects have already been made on @@ -174,6 +190,13 @@ export interface GalleryState { * happen on the next "file sync", until then they remain as in-memory state * in the reducer. */ + files: EnteFile[]; + /** + * The user's normal (non-hidden, non-trash) files, with any unsynced + * modifications also applied to them. + * + * The list is sorted so that newer files are first. + */ normalFiles: EnteFile[]; /** * The user's hidden files, with any unsynced modifications also applied to @@ -471,10 +494,12 @@ const initialGalleryState: GalleryState = { familyData: undefined, normalCollections: [], hiddenCollections: [], + lastSyncedFiles: [], lastSyncedNormalFiles: [], lastSyncedHiddenFiles: [], trashItems: [], peopleState: undefined, + files: [], normalFiles: [], hiddenFiles: [], archivedCollectionIDs: new Set(), @@ -513,12 +538,16 @@ const galleryReducer: React.Reducer = ( if (process.env.NEXT_PUBLIC_ENTE_TRACE) console.log("dispatch", action); switch (action.type) { case "mount": { + const lastSyncedFiles = sortFiles( + action.normalFiles.concat(action.hiddenFiles), + ); const lastSyncedNormalFiles = sortFiles(action.normalFiles); const lastSyncedHiddenFiles = sortFiles(action.hiddenFiles); const trashItems = sortTrashItems(action.trashItems); // During mount there are no unsynced updates, and we can directly // use the provided files. + const files = lastSyncedFiles; const normalFiles = lastSyncedNormalFiles; const hiddenFiles = lastSyncedHiddenFiles; @@ -545,9 +574,11 @@ const galleryReducer: React.Reducer = ( familyData: action.familyData, normalCollections, hiddenCollections, + lastSyncedFiles, lastSyncedNormalFiles, lastSyncedHiddenFiles, trashItems, + files, normalFiles, hiddenFiles, archivedCollectionIDs,