π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
refractor(reducer):create-archive-albums-mode
Aswin Asok3d2baad45695
diff --git a/web/apps/photos/src/components/FileList.tsx b/web/apps/photos/src/components/FileList.tsxindex 32cfd69c22..f4e60d85f8 100644--- a/web/apps/photos/src/components/FileList.tsx+++ b/web/apps/photos/src/components/FileList.tsx@@ -738,7 +738,8 @@ export const FileList: React.FC<FileListProps> = ({: {mode: (mode ?? "albums") as| "albums"- | "hidden-albums",+ | "hidden-albums"+ | "archive-albums",collectionID: activeCollectionID,};setSelected({diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 062df6daf5..e1302f842f 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -447,7 +447,9 @@ const Page: React.FC = () => {const activeCollectionFiles = useMemo(() => {if (!activeCollection) return [];- if (barMode == "hidden-albums") return filteredFiles;+ if (barMode == "hidden-albums" || barMode == "archive-albums") {+ return filteredFiles;+ }return filteredFiles.filter(({ id, magicMetadata }) => {const visibility = magicMetadata?.data.visibility;@@ -496,15 +498,12 @@ const Page: React.FC = () => {filteredFiles.length > 0 &&selectedFilesInView.length === filteredFiles.length;- const isInArchiveSection =- barMode == "albums" &&- (activeCollectionID == PseudoCollectionID.archiveItems ||- activeCollectionSummary?.attributes.has("archived"));+ const isInArchiveSection = barMode == "archive-albums";const barCollectionSummaries =barMode == "hidden-albums"? state.hiddenCollectionSummaries- : isInArchiveSection+ : barMode == "archive-albums"? state.archivedCollectionSummaries: state.normalCollectionSummaries;@@ -759,7 +758,10 @@ const Page: React.FC = () => {barMode == "people" && activePersonID? { mode: "people" as const, personID: activePersonID }: {- mode: barMode as "albums" | "hidden-albums",+ mode: barMode as+ | "albums"+ | "hidden-albums"+ | "archive-albums",collectionID: activeCollectionID!,},};@@ -786,7 +788,10 @@ const Page: React.FC = () => {barMode == "people" && activePersonID? { mode: "people" as const, personID: activePersonID }: {- mode: barMode as "albums" | "hidden-albums",+ mode: barMode as+ | "albums"+ | "hidden-albums"+ | "archive-albums",collectionID: activeCollectionID!,},};@@ -2054,7 +2059,7 @@ const Page: React.FC = () => {) : !isInSearchMode && isInArchiveSection ? (<SectionNavbarContentstitle={t("section_archive")}- onBack={() => dispatch({ type: "showAll" })}+ onBack={() => dispatch({ type: "showAlbums" })}onUpload={openUploader}/>) : (diff --git a/web/packages/new/photos/components/gallery/BarImpl.tsx b/web/packages/new/photos/components/gallery/BarImpl.tsxindex 3b323e44fb..0fa4ce6b48 100644--- a/web/packages/new/photos/components/gallery/BarImpl.tsx+++ b/web/packages/new/photos/components/gallery/BarImpl.tsx@@ -63,7 +63,7 @@ export interface GalleryBarImplProps {/*** The ID of the currently active collection (if any).*- * Required if mode is not "albums" or "hidden-albums".+ * Required if mode is not "people".*/activeCollectionID: number | undefined;/**@@ -198,6 +198,7 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({switch (mode) {case "albums":case "hidden-albums":+ case "archive-albums":i = collectionSummaries.findIndex(({ id }) => id == activeCollectionID,);@@ -211,7 +212,9 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({const itemData = useMemo<ItemData>(() =>- mode == "albums" || mode == "hidden-albums"+ mode == "albums" ||+ mode == "hidden-albums" ||+ mode == "archive-albums"? {type: "collections",collectionSummaries,@@ -357,10 +360,13 @@ export const Row2 = styled("div")`const ModeIndicator: React.FC<Pick<GalleryBarImplProps, "mode" | "onChangeMode">> = ({ mode, onChangeMode }) => {- // Mode switcher is not shown in the hidden albums section.+ // Mode switcher is not shown in section-specific album views.if (mode == "hidden-albums") {return <Typography>{t("hidden_albums")}</Typography>;}+ if (mode == "archive-albums") {+ return <Typography>{t("section_archive")}</Typography>;+ }// Show the static mode indicator with only the "Albums" title if ML is not// supported on this client (web), since there are no other sections todiff --git a/web/packages/new/photos/components/gallery/index.tsx b/web/packages/new/photos/components/gallery/index.tsxindex 809315dbaf..c2c66e2c87 100644--- a/web/packages/new/photos/components/gallery/index.tsx+++ b/web/packages/new/photos/components/gallery/index.tsx@@ -59,7 +59,10 @@ export interface RemotePullOpts {* and starts a new selection.* */export type SelectionContext =- | { mode: "albums" | "hidden-albums"; collectionID: number }+ | {+ mode: "albums" | "hidden-albums" | "archive-albums";+ collectionID: number;+ }| { mode: "people"; personID: string };interface SearchResultsHeaderProps {diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.tsindex 2247f712b4..30b1b3824c 100644--- a/web/packages/new/photos/components/gallery/reducer.ts+++ b/web/packages/new/photos/components/gallery/reducer.ts@@ -47,7 +47,11 @@ import type { FamilyData, UserDetails } from "../../services/user-details";* TODO: Deprecated(?). Use GalleryView instead. Deprecated if it can be used in* all cases where the bar mode was in use.*/-export type GalleryBarMode = "albums" | "hidden-albums" | "people";+export type GalleryBarMode =+ | "albums"+ | "hidden-albums"+ | "archive-albums"+ | "people";/*** Specifies what the gallery is currently displaying.@@ -57,17 +61,16 @@ export type GalleryBarMode = "albums" | "hidden-albums" | "people";export type GalleryView =| {/**- * We're either in the "Albums" or "Hidden albums" section.+ * We're in the Albums, Hidden albums, or Archive section.*/- type: "albums" | "hidden-albums";+ type: "albums" | "hidden-albums" | "archive-albums";activeCollectionSummaryID: number;/*** If the active collection ID is for a collection and not a* pseudo-collection, this property will be set to the corresponding* {@link Collection}.*- * It is guaranteed that this will be one of the {@link collections}- * or {@link hiddenCollections}.+ * It is guaranteed that this will be one of the {@link collections}.*/activeCollection: Collection | undefined;/**@@ -741,6 +744,13 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (hiddenCollectionSummaries,selectedCollectionSummaryID,));+ } else if (state.view?.type == "archive-albums") {+ ({ view, selectedCollectionSummaryID } =+ deriveArchiveAlbumsViewAndSelectedID(+ collections,+ archivedCollectionSummaries,+ selectedCollectionSummaryID,+ ));}return stateByUpdatingFilteredFiles({@@ -1109,6 +1119,22 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (activeCollectionSummaryID,)!,};+ } else if (+ selectedCollectionSummaryID !== undefined &&+ state.archivedCollectionSummaries.has(+ selectedCollectionSummaryID,+ )+ ) {+ const activeCollectionSummaryID = selectedCollectionSummaryID;+ view = {+ type: "archive-albums",+ activeCollectionSummaryID,+ activeCollection,+ activeCollectionSummary:+ state.archivedCollectionSummaries.get(+ activeCollectionSummaryID,+ )!,+ };} else {const activeCollectionSummaryID =selectedCollectionSummaryID ?? PseudoCollectionID.all;@@ -1868,9 +1894,15 @@ const deriveAlbumsViewAndSelectedID = (selectedCollectionSummaryID: GalleryState["selectedCollectionSummaryID"],) => {// Make sure that the last selected ID is still valid by searching for it.- const selectedCollectionSummary = selectedCollectionSummaryID+ const candidateCollectionSummary = selectedCollectionSummaryID? collectionSummaries.get(selectedCollectionSummaryID): undefined;+ const selectedCollectionSummary =+ candidateCollectionSummary &&+ !candidateCollectionSummary.attributes.has("archiveItems") &&+ !candidateCollectionSummary.attributes.has("archived")+ ? candidateCollectionSummary+ : undefined;const activeCollectionSummaryID =selectedCollectionSummary?.id ?? PseudoCollectionID.all;@@ -1929,6 +1961,41 @@ const deriveHiddenAlbumsViewAndSelectedID = (};};+/**+ * Sibling of {@link deriveAlbumsViewAndSelectedID} for when we're in the+ * archive albums section.+ */+const deriveArchiveAlbumsViewAndSelectedID = (+ collections: GalleryState["collections"],+ archivedCollectionSummaries: GalleryState["archivedCollectionSummaries"],+ selectedCollectionSummaryID: GalleryState["selectedCollectionSummaryID"],+) => {+ // Make sure that the last selected ID is still valid by searching for it.+ const selectedCollectionSummary = selectedCollectionSummaryID+ ? archivedCollectionSummaries.get(selectedCollectionSummaryID)+ : undefined;++ const activeCollectionSummaryID =+ selectedCollectionSummary?.id ?? PseudoCollectionID.archiveItems;+ const activeCollectionSummary = archivedCollectionSummaries.get(+ activeCollectionSummaryID,+ )!;+ const activeCollection =+ selectedCollectionSummary &&+ activeCollectionSummaryID != PseudoCollectionID.archiveItems+ ? collections.find(({ id }) => id == activeCollectionSummaryID)+ : undefined;+ return {+ selectedCollectionSummaryID: activeCollectionSummaryID,+ view: {+ type: "archive-albums" as const,+ activeCollectionSummaryID,+ activeCollection,+ activeCollectionSummary,+ },+ };+};+/*** Compute the {@link GalleryView} from its dependencies when we are switching* to (or back to) the "people" view.@@ -2098,7 +2165,9 @@ const stateByUpdatingFilteredFiles = (state: GalleryState) => {const visibleSearchFiles = suppressSharedFilesSavedByUser(searchFiles,state.user?.id,- state.view?.type == "albums" || state.view?.type == "hidden-albums"+ state.view?.type == "albums" ||+ state.view?.type == "hidden-albums" ||+ state.view?.type == "archive-albums"? state.view.activeCollection: undefined,);@@ -2111,7 +2180,8 @@ const stateByUpdatingFilteredFiles = (state: GalleryState) => {return { ...state, filteredFiles };} else if (state.view?.type == "albums" ||- state.view?.type == "hidden-albums"+ state.view?.type == "hidden-albums" ||+ state.view?.type == "archive-albums") {const filteredFiles = deriveAlbumsOrHiddenAlbumsFilteredFiles(state.trashItems,@@ -2141,7 +2211,7 @@ const stateByUpdatingFilteredFiles = (state: GalleryState) => {/*** Compute the sorted list of files to show when we're in the "albums" or- * "hidden-albums" view and the dependencies change.+ * "hidden-albums", or "archive-albums" view and the dependencies change.*/const deriveAlbumsOrHiddenAlbumsFilteredFiles = (trashItems: GalleryState["trashItems"],@@ -2152,7 +2222,10 @@ const deriveAlbumsOrHiddenAlbumsFilteredFiles = (archivedFileIDs: GalleryState["archivedFileIDs"],tempDeletedFileIDs: GalleryState["tempDeletedFileIDs"],tempHiddenFileIDs: GalleryState["tempHiddenFileIDs"],- view: Extract<GalleryView, { type: "albums" | "hidden-albums" }>,+ view: Extract<+ GalleryView,+ { type: "albums" | "hidden-albums" | "archive-albums" }+ >,currentUserID: number | undefined,) => {const activeCollectionSummaryID = view.activeCollectionSummaryID;diff --git a/web/packages/new/photos/utils/file-actions.ts b/web/packages/new/photos/utils/file-actions.tsindex 7e0a825aa3..e7582752e2 100644--- a/web/packages/new/photos/utils/file-actions.ts+++ b/web/packages/new/photos/utils/file-actions.ts@@ -32,7 +32,7 @@ export type FileContextAction =* Context needed to determine which file actions should be available.*/export interface FileActionContext {- /** The current bar mode (albums, hidden-albums, people). */+ /** The current bar mode (albums, hidden-albums, archive-albums, people). */barMode?: GalleryBarMode;/** Whether we're in search mode. */isInSearchMode: boolean;