π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
update(refractor):moving-archieve-logic-to-reducer
Aswin Asokb09b6ffb364d
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex bf38824cb1..419fa2fa9f 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -501,40 +501,12 @@ const Page: React.FC = () => {(activeCollectionID == PseudoCollectionID.archiveItems ||activeCollectionSummary?.attributes.has("archived"));- // TODO: Move into reducer- const barCollectionSummaries = useMemo(() => {- if (barMode == "hidden-albums") return state.hiddenCollectionSummaries;- if (!isInArchiveSection) return state.normalCollectionSummaries;-- const archiveCollectionSummaries = new Map(- [...state.normalCollectionSummaries].filter(- ([id, collectionSummary]) =>- id == PseudoCollectionID.archiveItems ||- collectionSummary.attributes.has("archived"),- ),- );- const archiveSummary = archiveCollectionSummaries.get(- PseudoCollectionID.archiveItems,- );- if (archiveSummary) {- archiveCollectionSummaries.set(PseudoCollectionID.archiveItems, {- ...archiveSummary,- coverFile:- archiveSummary.coverFile ?? archiveSummary.latestFile,- attributes: new Set(- [...archiveSummary.attributes].filter(- (attribute) => attribute != "hideFromCollectionBar",- ),- ),- });- }- return archiveCollectionSummaries;- }, [- barMode,- isInArchiveSection,- state.hiddenCollectionSummaries,- state.normalCollectionSummaries,- ]);+ const barCollectionSummaries =+ barMode == "hidden-albums"+ ? state.hiddenCollectionSummaries+ : isInArchiveSection+ ? state.archivedCollectionSummaries+ : state.normalCollectionSummaries;const router = useRouter();diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.tsindex 4e9f4f6d96..2247f712b4 100644--- a/web/packages/new/photos/components/gallery/reducer.ts+++ b/web/packages/new/photos/components/gallery/reducer.ts@@ -285,6 +285,11 @@ export interface GalleryState {* collections.*/hiddenCollectionSummaries: Map<number, CollectionSummary>;+ /**+ * A variant of {@link normalCollectionSummaries}, but for archived+ * collections and the archive section entry.+ */+ archivedCollectionSummaries: Map<number, CollectionSummary>;/*** The ID of the collection summary that should be shown when the user* navigates to the uncategorized section.@@ -526,6 +531,7 @@ const initialGalleryState: GalleryState = {shareSuggestionEmails: [],normalCollectionSummaries: new Map(),hiddenCollectionSummaries: new Map(),+ archivedCollectionSummaries: new Map(),uncategorizedCollectionSummaryID:PseudoCollectionID.uncategorizedPlaceholder,tempDeletedFileIDs: new Set(),@@ -592,6 +598,13 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (action.user,collectionFiles,);+ const archivedCollectionSummaries =+ deriveArchivedCollectionSummaries(+ normalCollections,+ action.user,+ collectionFiles,+ hiddenFileIDs,+ );const view = {type: "albums" as const,@@ -637,6 +650,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (),normalCollectionSummaries,hiddenCollectionSummaries,+ archivedCollectionSummaries,uncategorizedCollectionSummaryID:deriveUncategorizedCollectionSummaryID(normalCollections),view,@@ -700,6 +714,13 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (state.user!,state.collectionFiles,);+ const archivedCollectionSummaries =+ deriveArchivedCollectionSummaries(+ normalCollections,+ state.user!,+ state.collectionFiles,+ hiddenFileIDs,+ );// Revalidate the active view if needed.let view = state.view;@@ -753,6 +774,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (),normalCollectionSummaries,hiddenCollectionSummaries,+ archivedCollectionSummaries,uncategorizedCollectionSummaryID:deriveUncategorizedCollectionSummaryID(normalCollections),selectedCollectionSummaryID,@@ -1515,10 +1537,9 @@ const deriveNormalCollectionSummaries = (),);- const archiveItemsFiles = uniqueFilesByID(- collectionFiles.filter(- (f) => !hiddenFileIDs.has(f.id) && isArchivedFile(f),- ),+ const archiveItemsFiles = deriveArchiveItemsFiles(+ collectionFiles,+ hiddenFileIDs,);normalCollectionSummaries.set(PseudoCollectionID.all, {@@ -1573,6 +1594,16 @@ const pseudoCollectionOptionsForLatestFileAndCount = (updationTime: file?.updationTime,});+const deriveArchiveItemsFiles = (+ collectionFiles: GalleryState["collectionFiles"],+ hiddenFileIDs: GalleryState["hiddenFileIDs"],+) =>+ uniqueFilesByID(+ collectionFiles.filter(+ (file) => !hiddenFileIDs.has(file.id) && isArchivedFile(file),+ ),+ );+/*** Compute hidden collection summaries from their dependencies.*/@@ -1603,6 +1634,35 @@ const deriveHiddenCollectionSummaries = (return hiddenCollectionSummaries;};+/**+ * Compute archived collection summaries from their dependencies.+ */+const deriveArchivedCollectionSummaries = (+ normalCollections: Collection[],+ user: LocalUser,+ collectionFiles: GalleryState["collectionFiles"],+ hiddenFileIDs: GalleryState["hiddenFileIDs"],+) => {+ const archivedCollectionSummaries = createCollectionSummaries(+ user,+ normalCollections.filter(isArchivedCollection),+ collectionFiles,+ );++ archivedCollectionSummaries.set(PseudoCollectionID.archiveItems, {+ ...pseudoCollectionOptionsForFiles(+ deriveArchiveItemsFiles(collectionFiles, hiddenFileIDs),+ ),+ id: PseudoCollectionID.archiveItems,+ name: t("section_archive"),+ type: "archiveItems",+ attributes: new Set(["archiveItems", "system"]),+ sortPriority: CollectionSummarySortPriority.system,+ });++ return archivedCollectionSummaries;+};+/*** Return the ID of the collection summary that should be shown when the user* navigates to the uncategorized section.@@ -1957,18 +2017,26 @@ const stateForUpdatedCollectionFiles = (state: GalleryState,collectionFiles: GalleryState["collectionFiles"],): GalleryState => {+ const normalCollections = state.collections.filter(+ (c) => !state.hiddenCollectionIDs.has(c.id),+ );+ const hiddenCollections = state.collections.filter((c) =>+ state.hiddenCollectionIDs.has(c.id),+ );const hiddenFileIDs = deriveHiddenFileIDs(collectionFiles,state.hiddenCollectionIDs,);+ const archivedFileIDs = deriveArchivedFileIDs(+ state.archivedCollectionIDs,+ collectionFiles,+ );+return {...state,collectionFiles,hiddenFileIDs,- archivedFileIDs: deriveArchivedFileIDs(- state.archivedCollectionIDs,- collectionFiles,- ),+ archivedFileIDs,favoriteFileIDs: deriveFavoriteFileIDs(state.user!,state.collections,@@ -1980,22 +2048,24 @@ const stateForUpdatedCollectionFiles = (state.hiddenCollectionIDs,),normalCollectionSummaries: deriveNormalCollectionSummaries(- state.collections.filter(- (c) => !state.hiddenCollectionIDs.has(c.id),- ),+ normalCollections,state.user!,state.trashItems,collectionFiles,hiddenFileIDs,- state.archivedFileIDs,+ archivedFileIDs,),hiddenCollectionSummaries: deriveHiddenCollectionSummaries(- state.collections.filter((c) =>- state.hiddenCollectionIDs.has(c.id),- ),+ hiddenCollections,state.user!,collectionFiles,),+ archivedCollectionSummaries: deriveArchivedCollectionSummaries(+ normalCollections,+ state.user!,+ collectionFiles,+ hiddenFileIDs,+ ),pendingSearchSuggestions: enqueuePendingSearchSuggestionsIfNeeded(state.searchSuggestion,state.pendingSearchSuggestions,