π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[web][photos] Move gallery bar composition into gallery page
AswinAsoke919e41a02b1
diff --git a/web/apps/photos/src/components/collections/GalleryBarAndListHeader.tsx b/web/apps/photos/src/components/collections/GalleryListHeader.tsxsimilarity index 74%rename from web/apps/photos/src/components/collections/GalleryBarAndListHeader.tsxrename to web/apps/photos/src/components/collections/GalleryListHeader.tsxindex 3351d9380f..4101f51b54 100644--- a/web/apps/photos/src/components/collections/GalleryBarAndListHeader.tsx+++ b/web/apps/photos/src/components/collections/GalleryListHeader.tsx@@ -5,11 +5,8 @@ import {type CollectionShareProps,} from "@/components/collections/CollectionShare";import type { FileListHeaderOrFooter } from "@/components/FileList";-import {- GalleryBarImpl,- type GalleryBarImplProps,-} from "@/components/gallery/BarImpl";import { PeopleHeader } from "@/components/gallery/PeopleHeader";+import type { GalleryBarMode } from "@/components/gallery/reducer";import { useModalVisibility } from "ente-base/components/utils/modal";import type { Collection } from "ente-media/collection";import {@@ -20,6 +17,7 @@ import {PseudoCollectionID,type CollectionSummaries,} from "ente-new/photos/services/collection-summary";+import type { Person } from "ente-new/photos/services/ml/people";import React, { useCallback, useEffect, useState } from "react";import { AlbumCastDialog } from "./AlbumCastDialog";import {@@ -27,61 +25,43 @@ import {type CollectionHeaderProps,} from "./CollectionHeader";-export type GalleryBarAndListHeaderProps = GalleryBarImplProps & {- sortedPeople: GalleryBarImplProps["people"];+type GalleryListHeaderProps = {+ mode: GalleryBarMode;shouldHide: boolean;barCollectionSummaries: CollectionSummaries;activeCollection: Collection | undefined;+ activeCollectionID: number | undefined;+ activePerson: Person | undefined;+ people: Person[];setActiveCollectionID: (collectionID: number) => void;- onSelectPersonInHeader: GalleryBarImplProps["onSelectPerson"];+ onSelectPerson: (personID: string) => void;setFileListHeader: (header: FileListHeaderOrFooter) => void;hasActiveFileSelection: boolean;} & Pick<- CollectionHeaderProps,- | "isActiveCollectionDownloadInProgress"- | "onRemotePull"- | "onAddSaveGroup"- | "onEditAlbumDetails"- | "onShowMap"- | "onCollectionSlideshow"- > &+ CollectionHeaderProps,+ | "isActiveCollectionDownloadInProgress"+ | "onRemotePull"+ | "onAddSaveGroup"+ | "onEditAlbumDetails"+ | "onShowMap"+ | "onCollectionSlideshow"+> &Pick<CollectionShareProps,"user" | "emailByUserID" | "shareSuggestionEmails" | "setBlockingLoad">;-// TODO: Move this back into the gallery once its responsibilities are split.-export const GalleryBarAndListHeader: React.FC<- GalleryBarAndListHeaderProps-> = ({+export const GalleryListHeader: React.FC<GalleryListHeaderProps> = ({shouldHide,mode,user,barCollectionSummaries: toShowCollectionSummaries,- collectionSummaries,- visibleAlbumFilters,- collectionsSortBy,- onChangeCollectionsSortBy,- normalCollectionSummaries,- uncategorizedCollectionSummaryID,- onShowCollectionSummary,activeCollection,activeCollectionID,setActiveCollectionID,- onSelectCollectionID,setBlockingLoad,people,- sortedPeople,- peopleSortBy,- onChangePeopleSortBy,- albumFilter,- albumSearchQuery,- onAlbumSearchQueryChange,- onShowAlbumOverview,- onShowPeopleOverview,- onCreateAlbum,onSelectPerson,- onSelectPersonInHeader,isActiveCollectionDownloadInProgress,hasActiveFileSelection,activePerson,@@ -93,8 +73,6 @@ export const GalleryBarAndListHeader: React.FC<onShowMap,onCollectionSlideshow,setFileListHeader,- collapsed,- mobileDrawerProps,}) => {const { show: showCollectionShare, props: collectionShareVisibilityProps } =useModalVisibility();@@ -166,7 +144,7 @@ export const GalleryBarAndListHeader: React.FC<<PeopleHeaderperson={activePerson}people={people}- onSelectPerson={onSelectPersonInHeader}+ onSelectPerson={onSelectPerson}/>) : (<></>@@ -205,34 +183,6 @@ export const GalleryBarAndListHeader: React.FC<return (<>- <GalleryBarImpl- {...{- mode,- albumFilter,- albumSearchQuery,- onAlbumSearchQueryChange,- onShowAlbumOverview,- onShowPeopleOverview,- onCreateAlbum,- onSelectCollectionID,- onSelectPerson,- activeCollectionID,- people: sortedPeople,- activePerson,- collectionsSortBy,- onChangeCollectionsSortBy,- collectionSummaries,- visibleAlbumFilters,- peopleSortBy,- collapsed,- mobileDrawerProps,- normalCollectionSummaries,- uncategorizedCollectionSummaryID,- onShowCollectionSummary,- }}- onChangePeopleSortBy={onChangePeopleSortBy}- />-{activeCollection && (<><CollectionSharediff --git a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsxindex e4628feba5..16ad3c6693 100644--- a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx+++ b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx@@ -1,8 +1,4 @@import { CreateAlbumDialog } from "@/components/collections/CreateAlbumDialog";-import {- GalleryBarAndListHeader,- type GalleryBarAndListHeaderProps,-} from "@/components/collections/GalleryBarAndListHeader";import { SearchBar, type SearchBarProps } from "@/components/SearchBar";import { uploadManager } from "@/services/upload-manager";import {@@ -35,9 +31,26 @@ import { isMLSupported } from "ente-new/photos/services/ml";import { t } from "i18next";import { useCallback, useEffect, useState, type ReactNode } from "react";-import type { GalleryBarPresentationProps } from "./BarImpl";+import type { RemotePullOpts } from ".";+import type {+ GalleryBarImplProps,+ GalleryBarPresentationProps,+} from "./BarImpl";import type { GalleryBarMode } from "./reducer";+type GalleryBarRenderProps = GalleryBarPresentationProps &+ Pick<+ GalleryBarImplProps,+ "onCreateAlbum" | "onSelectCollectionID" | "onSelectPerson"+ >;++interface GalleryNavigation {+ activeCollectionID: number | undefined;+ onSelectCollectionID: (collectionID: number) => void;+ onRemotePull: (opts?: RemotePullOpts) => Promise<void>;+ renderGalleryBar: (props: GalleryBarRenderProps) => ReactNode;+}+type PhotosNavigationShellProps = SearchBarProps & {onSidebar: () => void;onUpload: () => void;@@ -52,22 +65,14 @@ export const PhotosNavigationShell: React.FC<showRail: boolean;showNormalNavigation: boolean;alternateHeader: ReactNode;- galleryBarProps:- | Omit<- GalleryBarAndListHeaderProps,- | keyof GalleryBarPresentationProps- | "onCreateAlbum"- | "onSelectCollectionID"- | "onSelectPersonInHeader"- >- | undefined;+ galleryNavigation: GalleryNavigation | undefined;}>> = ({showRail,showNormalNavigation,alternateHeader,- galleryBarProps,+ galleryNavigation,children,...props}) => {@@ -78,17 +83,18 @@ export const PhotosNavigationShell: React.FC<const { show: showMobileNavigation, props: mobileDrawerProps } =useModalVisibility();const { onClose: closeMobileNavigation } = mobileDrawerProps;- const { setActiveCollectionID, onSelectPerson } = galleryBarProps ?? {};+ const { onSelectCollectionID } = galleryNavigation ?? {};+ const { onSelectPerson } = props;const selectCollection = useCallback((id: number) => {- setActiveCollectionID?.(id);+ onSelectCollectionID?.(id);closeMobileNavigation();},- [setActiveCollectionID, closeMobileNavigation],+ [onSelectCollectionID, closeMobileNavigation],);const selectPerson = useCallback((id: string) => {- onSelectPerson?.(id);+ onSelectPerson(id);closeMobileNavigation();},[onSelectPerson, closeMobileNavigation],@@ -115,14 +121,15 @@ export const PhotosNavigationShell: React.FC<const reopeningSection =mobile &&mode == "albums" &&- galleryBarProps &&+ galleryNavigation &&!props.isInSearchMode &&(props.mode == "hidden-albums" || props.mode == "archive-albums");if (- galleryBarProps &&+ galleryNavigation &&!props.isInSearchMode &&((props.mode == mode &&- galleryBarProps.activeCollectionID != PseudoCollectionID.all) ||+ galleryNavigation.activeCollectionID !=+ PseudoCollectionID.all) ||reopeningSection)) {if (mobile) {@@ -205,13 +212,13 @@ export const PhotosNavigationShell: React.FC<isHome={props.mode == "albums" &&!props.isInSearchMode &&- galleryBarProps?.activeCollectionID ==+ galleryNavigation?.activeCollectionID ==PseudoCollectionID.all}onChangeMode={handleChangeMode}opensDialog={mobile}navigationOpen={- !!galleryBarProps &&+ !!galleryNavigation &&(mobile? mobileDrawerProps.open: !navigationCollapsed)@@ -228,27 +235,24 @@ export const PhotosNavigationShell: React.FC<flexDirection: { xs: "column", md: "row" },}}>- {galleryBarProps && (+ {galleryNavigation && (<>- <GalleryBarAndListHeader- {...galleryBarProps}- collapsed={+ {galleryNavigation.renderGalleryBar({+ collapsed:showRail &&- (!railOpen || navigationCollapsed)- }- mobileDrawerProps={mobileDrawerProps}- onCreateAlbum={openAlbumCreation}- onSelectCollectionID={selectCollection}- onSelectPerson={selectPerson}- onSelectPersonInHeader={- galleryBarProps.onSelectPerson- }- />- {!galleryBarProps.shouldHide && (+ (!railOpen || navigationCollapsed),+ mobileDrawerProps,+ onCreateAlbum: openAlbumCreation,+ onSelectCollectionID: selectCollection,+ onSelectPerson: selectPerson,+ })}+ {!props.isInSearchMode && (<CreateAlbumDialog{...albumNameInputVisibilityProps}isHidden={createInHiddenSection}- onRemotePull={galleryBarProps.onRemotePull}+ onRemotePull={+ galleryNavigation.onRemotePull+ }onSelectCollectionID={selectCollection}/>)}diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex c2fb3560d0..798f6e542e 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -27,6 +27,7 @@ import {EditAlbumDetailsDialog,type AlbumDetails,} from "@/components/collections/EditAlbumDetailsDialog";+import { GalleryListHeader } from "@/components/collections/GalleryListHeader";import { slideshowFiles } from "@/components/collections/album-slideshow";import {GalleryEmptyState,@@ -35,6 +36,7 @@ import {type RemotePullOpts,} from "@/components/gallery";import { AlbumsOverview } from "@/components/gallery/AlbumsOverview";+import { GalleryBarImpl } from "@/components/gallery/BarImpl";import { DuplicatesView } from "@/components/gallery/DuplicatesView";import { LargeFilesView } from "@/components/gallery/LargeFilesView";import { PeopleOverview } from "@/components/gallery/PeopleOverview";@@ -2129,6 +2131,11 @@ const Page: React.FC = () => {);const showNormalNavigation = !showSelectionBar;+ const selectGalleryCollection =+ barMode == "links"+ ? (collectionID: number) =>+ dispatch({ type: "selectLink", collectionID })+ : handleShowCollectionSummaryWithID;return (<FullScreenDropZone@@ -2180,57 +2187,93 @@ const Page: React.FC = () => {onSelectSearchOption={handleSelectSearchOption}onSelectPeople={handleShowPeople}onSelectPerson={handleSelectPerson}- galleryBarProps={+ galleryNavigation={isCleanupViewOpen? undefined: {- user,- // TODO: These are incorrect assertions, the types of the- // component need to be updated.- activeCollection: activeCollection!,- activeCollectionID: galleryBarActiveCollectionID!,- activePerson,- albumFilter,- albumSearchQuery,- onAlbumSearchQueryChange: setAlbumSearchQuery,- onShowAlbumOverview: handleShowAlbumOverview,- onShowPeopleOverview: handleShowPeople,- collectionSummaries: sidebarCollectionSummaries,- visibleAlbumFilters: sidebarAlbumFilters,- collectionsSortBy,- onChangeCollectionsSortBy,- peopleSortBy,- onChangePeopleSortBy: setPeopleSortBy,- setFileListHeader,- isActiveCollectionDownloadInProgress,- onAddSaveGroup,- onEditAlbumDetails: showEditAlbumDetails,- onShowMap: handleShowCollectionMap,- onCollectionSlideshow: startSlideshow,- mode: barMode,- shouldHide: isInSearchMode,- barCollectionSummaries,- normalCollectionSummaries,- uncategorizedCollectionSummaryID:- state.uncategorizedCollectionSummaryID,- onShowCollectionSummary: showCollectionSummary,- emailByUserID: state.emailByUserID,- shareSuggestionEmails:- state.shareSuggestionEmails,- people,- sortedPeople,- setBlockingLoad,- setActiveCollectionID:- barMode == "links"- ? (collectionID) =>- dispatch({- type: "selectLink",- collectionID,- })- : handleShowCollectionSummaryWithID,- hasActiveFileSelection,+ activeCollectionID: galleryBarActiveCollectionID,+ onSelectCollectionID: selectGalleryCollection,onRemotePull: remotePull,- onSelectPerson: handleSelectPerson,+ renderGalleryBar: (presentationProps) => (+ <>+ {!isInSearchMode && (+ <GalleryBarImpl+ {...presentationProps}+ {...{+ activePerson,+ albumFilter,+ albumSearchQuery,+ collectionsSortBy,+ onChangeCollectionsSortBy,+ normalCollectionSummaries,+ peopleSortBy,+ }}+ mode={barMode}+ activeCollectionID={+ galleryBarActiveCollectionID+ }+ onAlbumSearchQueryChange={+ setAlbumSearchQuery+ }+ onShowAlbumOverview={+ handleShowAlbumOverview+ }+ onShowPeopleOverview={+ handleShowPeople+ }+ collectionSummaries={+ sidebarCollectionSummaries+ }+ visibleAlbumFilters={+ sidebarAlbumFilters+ }+ uncategorizedCollectionSummaryID={+ state.uncategorizedCollectionSummaryID+ }+ onShowCollectionSummary={+ showCollectionSummary+ }+ onChangePeopleSortBy={+ setPeopleSortBy+ }+ people={sortedPeople}+ />+ )}+ <GalleryListHeader+ {...{+ user,+ activeCollection,+ activePerson,+ barCollectionSummaries,+ people,+ setBlockingLoad,+ setFileListHeader,+ hasActiveFileSelection,+ isActiveCollectionDownloadInProgress,+ onAddSaveGroup,+ }}+ mode={barMode}+ shouldHide={isInSearchMode}+ activeCollectionID={+ galleryBarActiveCollectionID+ }+ setActiveCollectionID={+ selectGalleryCollection+ }+ onSelectPerson={handleSelectPerson}+ onEditAlbumDetails={+ showEditAlbumDetails+ }+ onShowMap={handleShowCollectionMap}+ onCollectionSlideshow={startSlideshow}+ emailByUserID={state.emailByUserID}+ shareSuggestionEmails={+ state.shareSuggestionEmails+ }+ onRemotePull={remotePull}+ />+ </>+ ),}}alternateHeader={diff --git a/web/apps/photos/tests/album-navigation-data.test.tsx b/web/apps/photos/tests/album-navigation-data.test.tsxindex d497b021e4..d551028de2 100644--- a/web/apps/photos/tests/album-navigation-data.test.tsx+++ b/web/apps/photos/tests/album-navigation-data.test.tsx@@ -122,4 +122,40 @@ describe("album navigation data", () => {"empty-albums",]);});++ describe.each(["hidden-albums", "archive-albums"] as const)(+ "%s quick links",+ (mode) => {+ const summaries = () => {+ const quickLink = album(1, {+ name: "Trip link",+ attributes: new Set(["quickLink"]),+ });+ if (mode == "archive-albums")+ quickLink.attributes.add("archived");+ return [+ quickLink,+ album(2, { name: "Family" }),+ album(3, {+ attributes: new Set(["hideFromCollectionBar"]),+ }),+ album(PseudoCollectionID.hiddenItems),+ album(PseudoCollectionID.archiveItems),+ ];+ };++ test("lists quick links alongside albums while omitting system entries", () => {+ const data = navigationData(summaries(), { mode });+ expect(ids(data.sidebarCollectionSummaries)).toEqual([2, 1]);+ });++ test("finds quick links using the sidebar search", () => {+ const data = navigationData(summaries(), {+ mode,+ albumSearchQuery: " TRIP ",+ });+ expect(ids(data.sidebarCollectionSummaries)).toEqual([1]);+ });+ },+ );});diff --git a/web/apps/photos/tests/sidebar-quick-links.test.tsx b/web/apps/photos/tests/sidebar-quick-links.test.tsxdeleted file mode 100644index 86de1995a0..0000000000--- a/web/apps/photos/tests/sidebar-quick-links.test.tsx+++ /dev/null@@ -1,112 +0,0 @@-import type { CollectionSummary } from "ente-new/photos/services/collection-summary";-import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";-import { renderToStaticMarkup } from "react-dom/server";-import { beforeEach, describe, expect, test, vi } from "vitest";-import {- GalleryBarAndListHeader,- type GalleryBarAndListHeaderProps,-} from "../src/components/collections/GalleryBarAndListHeader";-import type { GalleryBarImplProps } from "../src/components/gallery/BarImpl";-import { useAlbumNavigationData } from "../src/components/gallery/use-album-navigation-data";--const { renderBar } = vi.hoisted(() => ({- renderBar: vi.fn<(props: GalleryBarImplProps) => null>(() => null),-}));--vi.mock("@/components/gallery/BarImpl", () => ({ GalleryBarImpl: renderBar }));-vi.mock("@/components/collections/CollectionShare", () => ({- CollectionShare: () => null,-}));-vi.mock("@/components/gallery/PeopleHeader", () => ({- PeopleHeader: () => null,-}));-vi.mock("../src/components/collections/AlbumCastDialog", () => ({- AlbumCastDialog: () => null,-}));-vi.mock("../src/components/collections/CollectionHeader", () => ({- CollectionHeader: () => null,-}));-vi.mock("@/utils/album-filters", () => import("../src/utils/album-filters"));-vi.mock("@/utils/people-sort", () => import("../src/utils/people-sort"));--const album = (- id: number,- name: string,- attributes: CollectionSummary["attributes"] = new Set(),-): CollectionSummary => ({- id,- name,- type: "album",- attributes,- fileCount: 1,- latestFile: undefined,- coverFile: undefined,- updationTime: undefined,- sortPriority: 0,-});--const renderSidebar = (- mode: "hidden-albums" | "archive-albums",- albumSearchQuery = "",-) => {- const quickLink = album(1, "Trip link", new Set(["quickLink"]));- if (mode == "archive-albums") quickLink.attributes.add("archived");- const summaries = [- quickLink,- album(2, "Family"),- album(3, "Hidden system album", new Set(["hideFromCollectionBar"])),- album(PseudoCollectionID.hiddenItems, "Hidden items"),- album(PseudoCollectionID.archiveItems, "Archive items"),- ];- const props = {- mode,- albumFilter: "ente",- albumSearchQuery,- barCollectionSummaries: new Map(summaries.map((cs) => [cs.id, cs])),- uncategorizedCollectionSummaryID: 99,- people: [],- sortedPeople: [],- peopleSortBy: "name-asc",- isActiveCollectionDownloadInProgress: vi.fn(() => false),- setActiveCollectionID: vi.fn(),- onSelectCollectionID: vi.fn(),- onSelectPerson: vi.fn(),- onSelectPersonInHeader: vi.fn(),- onCreateAlbum: vi.fn(),- mobileDrawerProps: { open: true, onClose: vi.fn() },- } as unknown as GalleryBarAndListHeaderProps;- const Sidebar = () => {- const data = useAlbumNavigationData({- ...props,- collectionSummaries: props.barCollectionSummaries,- });- return (- <GalleryBarAndListHeader- {...props}- {...data}- collectionSummaries={data.sidebarCollectionSummaries}- />- );- };- renderToStaticMarkup(<Sidebar />);- return { props, bar: renderBar.mock.lastCall![0] };-};--beforeEach(() => vi.clearAllMocks());--describe.each(["hidden-albums", "archive-albums"] as const)(- "%s quick links",- (mode) => {- test("lists quick links alongside albums while omitting system entries", () => {- const { bar, props } = renderSidebar(mode);- expect(bar.collectionSummaries.map(({ id }) => id)).toEqual([1, 2]);- bar.onSelectCollectionID(1);- expect(props.onSelectCollectionID).toHaveBeenCalledWith(1);- });-- test("finds quick links using the sidebar search", () => {- const { bar } = renderSidebar(mode, " TRIP ");- expect(bar.collectionSummaries.map(({ id }) => id)).toEqual([1]);- });- },-);diff --git a/web/checks/lint-exceptions/suppressions.json b/web/checks/lint-exceptions/suppressions.jsonindex c78b9ec55a..92407e9a0b 100644--- a/web/checks/lint-exceptions/suppressions.json+++ b/web/checks/lint-exceptions/suppressions.json@@ -14,7 +14,7 @@"web/apps/photos/src/components/collections/CollectionShare.tsx": ["@typescript-eslint/no-unnecessary-condition"],- "web/apps/photos/src/components/collections/GalleryBarAndListHeader.tsx": [+ "web/apps/photos/src/components/collections/GalleryListHeader.tsx": ["react-hooks/exhaustive-deps"],"web/apps/photos/src/components/PlanSelector.tsx": [