π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[photos][web] Show album group overviews in the gallery
AswinAsokaeed09e8709b
diff --git a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsxindex aedcc6d58e..3400e4e7be 100644--- a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx+++ b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx@@ -25,14 +25,11 @@ import {GalleryItemsSummary,} from "ente-new/photos/components/gallery/ListHeader";import {- collectionsSortBy,PseudoCollectionID,sortCollectionSummaries,- type CollectionsSortBy,type CollectionSummaries,} from "ente-new/photos/services/collection-summary";import type { Person } from "ente-new/photos/services/ml/people";-import { includes } from "ente-utils/type-guards";import React, { useCallback, useEffect, useMemo, useState } from "react";import { AlbumCastDialog } from "./AlbumCastDialog";import {@@ -44,8 +41,6 @@ export type GalleryBarAndListHeaderProps = Omit<GalleryBarImplProps,| "collectionSummaries"| "onSelectCollectionID"- | "collectionsSortBy"- | "onChangeCollectionsSortBy"| "onShowAllAlbums"| "onShowAllPeople"> & {@@ -89,6 +84,12 @@ export const GalleryBarAndListHeader: React.FC<people,peopleSortBy,onChangePeopleSortBy,+ collectionsSortBy,+ onChangeCollectionsSortBy,+ albumFilter,+ albumSearchQuery,+ onAlbumSearchQueryChange,+ onShowAlbumOverview,onSelectPerson,allPeople,saveGroups,@@ -132,9 +133,6 @@ export const GalleryBarAndListHeader: React.FC<collectionShareVisibilityProps.onClose();}, [collectionShareVisibilityProps]);- const [collectionsSortBy, setCollectionsSortBy] =- useCollectionsSortByLocalState("updation-time-desc");-const sortedCollectionSummaries = useMemo(() =>sortCollectionSummaries(@@ -260,6 +258,10 @@ export const GalleryBarAndListHeader: React.FC<<GalleryBarImpl{...{mode,+ albumFilter,+ albumSearchQuery,+ onAlbumSearchQueryChange,+ onShowAlbumOverview,activeCollectionID,people: sortedPeople,activePerson,@@ -273,7 +275,7 @@ export const GalleryBarAndListHeader: React.FC<}}onSelectCollectionID={selectCollection}onSelectPerson={selectPerson}- onChangeCollectionsSortBy={setCollectionsSortBy}+ onChangeCollectionsSortBy={onChangeCollectionsSortBy}onChangePeopleSortBy={onChangePeopleSortBy}onShowAllAlbums={showAllAlbums}onShowAllPeople={showAllPeople}@@ -297,7 +299,7 @@ export const GalleryBarAndListHeader: React.FC<(cs) => !cs.attributes.has("system"),)}onSelectCollectionID={selectCollection}- onChangeCollectionsSortBy={setCollectionsSortBy}+ onChangeCollectionsSortBy={onChangeCollectionsSortBy}collectionsSortBy={collectionsSortBy}isInHiddenSection={mode == "hidden-albums"}isInArchiveSection={mode == "archive-albums"}@@ -339,21 +341,3 @@ export const GalleryBarAndListHeader: React.FC<</>);};--const useCollectionsSortByLocalState = (initialValue: CollectionsSortBy) => {- const key = "collectionsSortBy";-- const [value, setValue] = useState(initialValue);-- useEffect(() => {- const value = localStorage.getItem(key);- if (value && includes(collectionsSortBy, value)) setValue(value);- }, []);-- const setter = (value: CollectionsSortBy) => {- localStorage.setItem(key, value);- setValue(value);- };-- return [value, setter] as const;-};diff --git a/web/apps/photos/src/components/gallery/AlbumsOverview.tsx b/web/apps/photos/src/components/gallery/AlbumsOverview.tsxnew file mode 100644index 0000000000..141e39a124--- /dev/null+++ b/web/apps/photos/src/components/gallery/AlbumsOverview.tsx@@ -0,0 +1,361 @@+import type { AlbumFilter } from "@/utils/album-filters";+import AddIcon from "@mui/icons-material/Add";+import PushPinIcon from "@mui/icons-material/PushPin";+import {+ Box,+ Stack,+ Typography,+ styled,+ useMediaQuery,+ useTheme,+} from "@mui/material";+import { ItemCard } from "ente-new/photos/components/Tiles";+import { UnstyledButton } from "ente-new/photos/components/UnstyledButton";+import type { CollectionSummary } from "ente-new/photos/services/collection-summary";+import { t } from "i18next";+import { useEffect, useRef, useState } from "react";+import AutoSizer from "react-virtualized-auto-sizer";+import { FixedSizeList, type ListChildComponentProps } from "react-window";++interface AlbumsOverviewProps {+ albums: CollectionSummary[];+ title: string;+ filter: AlbumFilter;+ hasSearchQuery: boolean;+ onSelectAlbum: (id: number) => void;+ onCreateAlbum: () => void;+}++/** Uses the People overview's virtualized rows with the ZIP's fixed album tiles. */+export const AlbumsOverview = ({+ albums,+ title,+ filter,+ hasSearchQuery,+ onSelectAlbum,+ onCreateAlbum,+}: AlbumsOverviewProps) => {+ const compact = useMediaQuery(useTheme().breakpoints.down("md"));+ const listRef = useRef<FixedSizeList>(null);+ const [listElement, setListElement] = useState<HTMLDivElement | null>(null);+ const [scrollbarWidth, setScrollbarWidth] = useState(0);+ useEffect(() => {+ if (!listElement) return;+ const measure = () =>+ setScrollbarWidth(+ listElement.offsetWidth - listElement.clientWidth,+ );+ measure();+ const observer = new ResizeObserver(measure);+ observer.observe(listElement);+ return () => observer.disconnect();+ }, [listElement]);+ const showCreate = filter == "ente" && !hasSearchQuery;+ const tileWidth = compact ? 104 : 140;+ const columnGap = compact ? 12 : 22;+ const rowGap = compact ? 16 : 24;+ // Cover + label gap + name + metadata gap + count.+ const cardHeight = tileWidth + 8 + 20 + 2 + 16;+ const displayTitle =+ filter == "shared"+ ? t("album_overview_shared_title")+ : filter == "received"+ ? t("album_overview_received_title")+ : title;++ useEffect(() => {+ listRef.current?.scrollTo(0);+ }, [filter, albums]);++ return (+ <Stack+ sx={{+ flex: 1,+ minHeight: 0,+ overflow: "hidden",+ px: { xs: "14px", md: "24px" },+ pb: { xs: "16px", md: "36px" },+ gap: "24px",+ }}+ >+ <Stack+ sx={{+ flexShrink: 0,+ minHeight: 54,+ justifyContent: "center",+ gap: "2px",+ }}+ >+ <Typography+ component="h1"+ sx={{+ fontFamily: '"Outfit Variable", Outfit, sans-serif',+ fontSize: { xs: 20, md: 24 },+ lineHeight: { xs: "26px", md: "32px" },+ fontWeight: 600,+ }}+ >+ {displayTitle}+ </Typography>+ <Typography+ sx={{+ fontSize: { xs: 12, md: 14 },+ lineHeight: "20px",+ color: "text.muted",+ }}+ >+ {t("album_overview_count", { count: albums.length })}+ </Typography>+ </Stack>+ {!albums.length && !showCreate ? (+ <Typography+ role="status"+ sx={{ color: "text.muted", fontSize: 14 }}+ >+ {t("no_results")}+ </Typography>+ ) : (+ <Box+ sx={{+ flex: 1,+ minHeight: 0,+ "--album-tile-width": `${tileWidth}px`,+ "--album-name-size": compact ? "13px" : "14px",+ "--album-count-size": compact ? "11px" : "12px",+ }}+ >+ <AutoSizer>+ {({ width, height }) => {+ // Account for the actual scrollbar without wasting a column on narrow windows.+ const columns = Math.max(+ 1,+ Math.floor(+ (width - scrollbarWidth + columnGap) /+ (tileWidth + columnGap),+ ),+ );+ return (+ <FixedSizeList+ ref={listRef}+ outerRef={setListElement}+ width={width}+ height={height}+ itemCount={Math.ceil(+ (albums.length + Number(showCreate)) /+ columns,+ )}+ itemSize={cardHeight + rowGap}+ overscanCount={1}+ useIsScrolling+ style={{ overflowX: "hidden" }}+ itemData={{+ albums,+ columns,+ columnGap,+ tileWidth,+ showCreate,+ onSelectAlbum,+ onCreateAlbum,+ }}+ >+ {AlbumsRow}+ </FixedSizeList>+ );+ }}+ </AutoSizer>+ </Box>+ )}+ </Stack>+ );+};++interface AlbumRowData {+ albums: CollectionSummary[];+ columns: number;+ columnGap: number;+ tileWidth: number;+ showCreate: boolean;+ onSelectAlbum: (id: number) => void;+ onCreateAlbum: () => void;+}++const AlbumsRow = ({+ data,+ index,+ style,+ isScrolling,+}: ListChildComponentProps<AlbumRowData>) => {+ const start = index * data.columns;+ const end = Math.min(+ start + data.columns,+ data.albums.length + Number(data.showCreate),+ );+ return (+ <div+ style={{+ ...style,+ display: "grid",+ gridTemplateColumns: `repeat(${data.columns}, ${data.tileWidth}px)`,+ columnGap: data.columnGap,+ alignItems: "start",+ }}+ >+ {Array.from({ length: end - start }, (_, offset) => {+ const album = data.albums[start + offset];+ if (!album)+ return (+ <AlbumButton key="create" onClick={data.onCreateAlbum}>+ <Cover+ sx={{+ border: "1.5px dashed",+ borderColor: "stroke.faint",+ display: "flex",+ alignItems: "center",+ justifyContent: "center",+ color: "text.muted",+ }}+ >+ <AddIcon />+ </Cover>+ <Typography+ component="span"+ sx={{+ fontSize: "var(--album-name-size)",+ lineHeight: "20px",+ fontWeight: 500,+ color: "text.muted",+ }}+ >+ {t("new_album")}+ </Typography>+ </AlbumButton>+ );+ const badge = album.attributes.has("sharedIncoming")+ ? t("album_overview_received_title")+ : album.attributes.has("sharedOutgoing") ||+ album.attributes.has("sharedViaLink")+ ? t("shared_albums_label")+ : undefined;+ return (+ <AlbumButton+ key={album.id}+ title={album.name}+ onClick={() => data.onSelectAlbum(album.id)}+ >+ <ItemCard+ TileComponent={Cover}+ coverFile={album.coverFile}+ isScrolling={isScrolling}+ >+ {badge && (+ <Box+ component="span"+ sx={{+ position: "absolute",+ right: 8,+ bottom: 8,+ height: 24,+ px: "8px",+ borderRadius: "8px",+ bgcolor: "rgba(0,0,0,.55)",+ color: "#fff",+ fontSize: 11,+ fontWeight: 600,+ display: "flex",+ alignItems: "center",+ backdropFilter: "blur(6px)",+ maxWidth: "calc(100% - 16px)",+ overflow: "hidden",+ whiteSpace: "nowrap",+ }}+ >+ {badge}+ </Box>+ )}+ </ItemCard>+ <Stack+ component="span"+ sx={{ width: "100%", gap: "2px" }}+ >+ <Stack+ component="span"+ direction="row"+ sx={{+ alignItems: "center",+ gap: "4px",+ minWidth: 0,+ }}+ >+ <Typography+ component="span"+ noWrap+ sx={{+ fontSize: "var(--album-name-size)",+ lineHeight: "20px",+ fontWeight: 500,+ }}+ >+ {album.name}+ </Typography>+ {(album.attributes.has("pinned") ||+ album.attributes.has("shareePinned")) && (+ <PushPinIcon+ sx={{+ flexShrink: 0,+ fontSize: 12,+ color: "text.faint",+ }}+ />+ )}+ </Stack>+ <Typography+ component="span"+ sx={{+ fontSize: "var(--album-count-size)",+ lineHeight: "16px",+ fontWeight: 500,+ color: "text.muted",+ }}+ >+ {t("album_items_count", {+ count: album.fileCount,+ })}+ </Typography>+ </Stack>+ </AlbumButton>+ );+ })}+ </div>+ );+};++const AlbumButton = styled(UnstyledButton)(({ theme }) => ({+ width: "var(--album-tile-width)",+ display: "flex",+ flexDirection: "column",+ alignItems: "flex-start",+ gap: 8,+ color: theme.vars.palette.text.base,+ textAlign: "left",+ borderRadius: 12,+ "&:hover": { opacity: 0.86 },+ "&:focus-visible": {+ outline: `2px solid ${theme.vars.palette.stroke.base}`,+ outlineOffset: -2,+ },+}));++const Cover = styled("div")({+ width: "var(--album-tile-width)",+ height: "var(--album-tile-width)",+ flexShrink: 0,+ borderRadius: 12,+ overflow: "hidden",+ position: "relative",+ "& > img": {+ width: "100%",+ height: "100%",+ objectFit: "cover",+ display: "block",+ },+});diff --git a/web/apps/photos/src/components/gallery/BarImpl.tsx b/web/apps/photos/src/components/gallery/BarImpl.tsxindex db2ca88c6c..b2459fdc33 100644--- a/web/apps/photos/src/components/gallery/BarImpl.tsx+++ b/web/apps/photos/src/components/gallery/BarImpl.tsx@@ -1,8 +1,8 @@import { CollectionsSortOptions } from "@/components/CollectionsSortOptions";import { PeopleSortOptions } from "@/components/PeopleSortOptions";import {+ filterAlbumSummaries,visibleAlbumFilters as getVisibleAlbumFilters,- matchesAlbumFilter,type AlbumFilter,} from "@/utils/album-filters";import type { PeopleSortBy } from "@/utils/people-sort";@@ -71,6 +71,10 @@ export interface GalleryBarPresentationProps {export interface GalleryBarImplProps extends GalleryBarPresentationProps {mode: GalleryBarMode;+ albumFilter: AlbumFilter;+ albumSearchQuery: string;+ onAlbumSearchQueryChange: (query: string) => void;+ onShowAlbumOverview: (filter: AlbumFilter) => void;collectionSummaries: CollectionSummary[];normalCollectionSummaries: CollectionSummaries;uncategorizedCollectionSummaryID: number;@@ -93,6 +97,10 @@ export interface GalleryBarImplProps extends GalleryBarPresentationProps {export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({mode,+ albumFilter,+ albumSearchQuery,+ onAlbumSearchQueryChange,+ onShowAlbumOverview,collectionSummaries,normalCollectionSummaries,uncategorizedCollectionSummaryID,@@ -115,11 +123,13 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({const titleID = useId();const listRef = useRef<FixedSizeList | null>(null);const searchInputRef = useRef<HTMLInputElement>(null);- const [searchQuery, setSearchQuery] = useState("");+ const [peopleSearchQuery, setPeopleSearchQuery] = useState("");+ const searchQuery = mode == "albums" ? albumSearchQuery : peopleSearchQuery;+ const setSearchQuery =+ mode == "albums" ? onAlbumSearchQueryChange : setPeopleSearchQuery;const canSearch = mode == "albums" || mode == "people";const normalizedSearchQuery = searchQuery.trim().toLowerCase();const isSearching = canSearch && !!normalizedSearchQuery;- const isSearchingAlbums = mode == "albums" && isSearching;const matchingPeople = useMemo(() =>mode == "people" && isSearching@@ -131,74 +141,42 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({: people,[mode, people, isSearching, normalizedSearchQuery],);- const matchingCollectionSummaries = useMemo(() => {- if (!isSearchingAlbums) return collectionSummaries;- const search = normalizedSearchQuery;- return collectionSummaries.filter((cs) =>- cs.name.toLowerCase().includes(search),- );- }, [collectionSummaries, normalizedSearchQuery, isSearchingAlbums]);const [viewportHeight, setViewportHeight] = useState(0);- const [albumFilter, setAlbumFilter] = useState<AlbumFilter | undefined>(- "ente",- );- const [searchAlbumFilter, setSearchAlbumFilter] = useState<- AlbumFilter | null | undefined- >(null);+ const [expandedAlbumFilter, setExpandedAlbumFilter] = useState<+ AlbumFilter | undefined+ >(albumFilter);++ useEffect(() => {+ setExpandedAlbumFilter(albumFilter);+ }, [albumFilter]);const visibleAlbumFilters = useMemo(- () =>- getVisibleAlbumFilters(collectionSummaries).filter(- ({ value }) =>- !isSearchingAlbums ||- matchingCollectionSummaries.some((cs) =>- matchesAlbumFilter(cs, value),- ),- ),- [collectionSummaries, isSearchingAlbums, matchingCollectionSummaries],+ () => getVisibleAlbumFilters(collectionSummaries),+ [collectionSummaries],);- const selectedAlbumFilter = isSearchingAlbums- ? searchAlbumFilter === null- ? (albumFilter ?? visibleAlbumFilters[0]?.value)- : searchAlbumFilter- : albumFilter;- const activeAlbumFilter =- selectedAlbumFilter === undefined ||- visibleAlbumFilters.some(({ value }) => value == selectedAlbumFilter)- ? selectedAlbumFilter- : visibleAlbumFilters[0]?.value;- const setActiveAlbumFilter = isSearchingAlbums- ? setSearchAlbumFilter- : setAlbumFilter;const visibleCollectionSummaries = useMemo(() =>- mode != "albums"- ? collectionSummaries- : matchingCollectionSummaries.filter(- (cs) =>- activeAlbumFilter !== undefined &&- matchesAlbumFilter(cs, activeAlbumFilter),- ),- [- mode,- collectionSummaries,- matchingCollectionSummaries,- activeAlbumFilter,- ],+ mode == "albums"+ ? filterAlbumSummaries(+ collectionSummaries,+ albumFilter,+ albumSearchQuery,+ )+ : collectionSummaries,+ [mode, collectionSummaries, albumFilter, albumSearchQuery],);useEffect(() => {- if (!isSearchingAlbums) setSearchAlbumFilter(null);- if (!isSearchingAlbums && albumFilter != activeAlbumFilter)- setAlbumFilter(activeAlbumFilter);- }, [albumFilter, activeAlbumFilter, isSearchingAlbums]);-- useEffect(() => {- setSearchQuery("");+ setPeopleSearchQuery("");}, [mode]);useEffect(() => {- if (mobile ? !mobileDrawerProps.open : collapsed) setSearchQuery("");- }, [mobile, mobileDrawerProps.open, collapsed]);+ if (+ mode == "people" &&+ (mobile ? !mobileDrawerProps.open : collapsed)+ ) {+ setPeopleSearchQuery("");+ }+ }, [mode, mobile, mobileDrawerProps.open, collapsed]);useEffect(() => {if (isSearching) listRef.current?.scrollTo(0);@@ -502,8 +480,7 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({)}</Stack>)}- {(isSearchingAlbums && !visibleAlbumFilters.length) ||- (mode == "people" && isSearching && !matchingPeople.length) ? (+ {mode == "people" && isSearching && !matchingPeople.length ? (<Typographyrole="status"sx={{ px: "16px", color: "text.muted" }}@@ -526,28 +503,30 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({<React.Fragment key={filter.value}><BarCardaria-label={filter.title()}+ aria-current={+ activeCollectionID === undefined &&+ albumFilter == filter.value+ ? "page"+ : undefined+ }aria-expanded={- activeAlbumFilter == filter.value+ expandedAlbumFilter == filter.value}aria-controls={- activeAlbumFilter == filter.value+ expandedAlbumFilter == filter.value? albumListID: undefined}- onClick={() =>- setActiveAlbumFilter(- activeAlbumFilter == filter.value+ onClick={() => {+ setExpandedAlbumFilter((current) =>+ current == filter.value? undefined: filter.value,- )- }- sx={{- flexShrink: 0,- bgcolor:- activeAlbumFilter == filter.value- ? "var(--gallery-navigation-surface)"- : undefined,+ );+ onShowAlbumOverview(filter.value);+ mobileDrawerProps.onClose();}}+ sx={{ flexShrink: 0 }}><CardText>{filter.label()}</CardText><ExpandMoreIcon@@ -555,13 +534,13 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({fontSize: 16,color: "text.muted",transform:- activeAlbumFilter == filter.value+ expandedAlbumFilter == filter.value? undefined: "rotate(-90deg)",}}/></BarCard>- {activeAlbumFilter == filter.value && items}+ {expandedAlbumFilter == filter.value && items}</React.Fragment>))}</Stack>@@ -840,7 +819,7 @@ const BarCard = styled(ButtonBase)(({ theme }) => ({borderRadius: "12px",color: theme.vars.palette.text.base,textAlign: "left",- '&[aria-current="true"]': {+ '&[aria-current="true"], &[aria-current="page"]': {backgroundColor: "var(--gallery-navigation-surface)",},"&:hover": { backgroundColor: "var(--gallery-navigation-hover)" },diff --git a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsxindex 85dd2a1796..307b11c147 100644--- a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx+++ b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx@@ -94,7 +94,9 @@ export const PhotosNavigationShell: React.FC<if (galleryBarProps &&!props.isInSearchMode &&- (props.mode == mode || reopeningSection)+ ((props.mode == mode &&+ galleryBarProps.activeCollectionID != PseudoCollectionID.all) ||+ reopeningSection)) {if (mobile) {if (mobileDrawerProps.open) closeMobileNavigation();diff --git a/web/apps/photos/src/components/gallery/reducer.ts b/web/apps/photos/src/components/gallery/reducer.tsindex d73d247ead..e07e0dcf73 100644--- a/web/apps/photos/src/components/gallery/reducer.ts+++ b/web/apps/photos/src/components/gallery/reducer.ts@@ -1,3 +1,4 @@+import type { AlbumFilter } from "@/utils/album-filters";import type { LocalUser } from "ente-accounts/services/user";import {groupFilesByCollectionID,@@ -50,6 +51,7 @@ export type GalleryBarMode ="albums" | "hidden-albums" | "archive-albums" | "people";type GalleryView =+ | { type: "album-overview"; albumFilter: AlbumFilter }| {type: "albums" | "hidden-albums" | "archive-albums";activeCollectionSummaryID: number;@@ -152,6 +154,7 @@ type GalleryAction =| { type: "clearUnsyncedState" }| { type: "showAll" }| { type: "showHidden" }+ | { type: "showAlbumOverview"; albumFilter: AlbumFilter }| { type: "showAlbums" }| { type: "showCollectionSummary"; collectionSummaryID: number | undefined }| { type: "showPeople" }@@ -162,7 +165,7 @@ type GalleryAction =| { type: "exitSearch"; shouldExitSearchMode?: boolean }| { type: "setSearchSortOrder"; asc: boolean | undefined };-const initialGalleryState: GalleryState = {+export const initialGalleryState: GalleryState = {user: undefined,familyData: undefined,collections: [],@@ -204,7 +207,7 @@ const initialGalleryState: GalleryState = {searchSortAsc: undefined,};-const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (+export const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (state,action,) => {@@ -712,6 +715,22 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (isInSearchMode: false,});+ case "showAlbumOverview":+ return stateByUpdatingFilteredFiles({+ ...state,+ selectedCollectionSummaryID: undefined,+ extraVisiblePerson: undefined,+ searchSuggestion: undefined,+ searchResults: undefined,+ isRecomputingSearchResults: false,+ pendingSearchSuggestions: [],+ view: {+ type: "album-overview",+ albumFilter: action.albumFilter,+ },+ isInSearchMode: false,+ });+case "showAlbums": {const { view, selectedCollectionSummaryID } =deriveAlbumsViewAndSelectedID(@@ -1663,6 +1682,8 @@ const stateByUpdatingFilteredFiles = (state: GalleryState) => {state.user?.id,);return { ...state, filteredFiles };+ } else if (state.view?.type == "album-overview") {+ return { ...state, filteredFiles: [] };} else if (state.view?.type == "people") {const filteredFiles = derivePeopleFilteredFiles(state.collectionFiles,diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 315f288814..0bfdbed9d0 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -34,6 +34,7 @@ import {SearchResultsHeader,type RemotePullOpts,} from "@/components/gallery";+import { AlbumsOverview } from "@/components/gallery/AlbumsOverview";import { DuplicatesView } from "@/components/gallery/DuplicatesView";import { LargeFilesView } from "@/components/gallery/LargeFilesView";import { PeopleOverview } from "@/components/gallery/PeopleOverview";@@ -58,7 +59,14 @@ import { useIsOffline } from "@/components/utils/use-is-offline";import { shouldShowWhatsNew } from "@/services/changelog";import exportService from "@/services/export";import { processPendingAlbumJoin } from "@/services/join-album";+import {+ albumFilters,+ filterAlbumSummaries,+ visibleAlbumFilters,+ type AlbumFilter,+} from "@/utils/album-filters";import type { PeopleSortBy } from "@/utils/people-sort";+import { useCollectionsSortByLocalState } from "@/utils/use-collections-sort";import CheckCircleIcon from "@mui/icons-material/CheckCircle";import { Link, Typography } from "@mui/material";import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";@@ -123,6 +131,7 @@ import {import {haveOnlySystemCollections,PseudoCollectionID,+ sortCollectionSummaries,} from "ente-new/photos/services/collection-summary";import {updateFilesLocation,@@ -213,6 +222,11 @@ const Page: React.FC = () => {collectionID: 0,context: { mode: "albums", collectionID: PseudoCollectionID.all },});+ const [albumFilter, setAlbumFilter] = useState<AlbumFilter>("ente");+ const [albumSearchQuery, setAlbumSearchQuery] = useState("");+ const [collectionsSortBy, setCollectionsSortBy] =+ useCollectionsSortByLocalState("updation-time-desc");+ const createForAlbumOverview = useRef(false);const [blockingLoad, setBlockingLoad] = useState(false);const [peopleSortBy, setPeopleSortBy] =useState<PeopleSortBy>("count-desc");@@ -419,19 +433,29 @@ const Page: React.FC = () => {filteredFiles,} = state;- const barMode = state.view?.type ?? "albums";+ const isAlbumOverview = state.view?.type == "album-overview";+ const barMode =+ state.view?.type == "album-overview"+ ? "albums"+ : (state.view?.type ?? "albums");+ const overviewFilter =+ state.view?.type == "album-overview"+ ? state.view.albumFilter+ : undefined;const quickLinkVisibility =barMode == "hidden-albums"? ItemVisibility.hidden: ItemVisibility.visible;const activeCollectionID =- state.view?.type == "people"+ state.view?.type == "people" || state.view?.type == "album-overview"? undefined: state.view?.activeCollectionSummaryID;const activeCollection =- state.view?.type == "people" ? undefined : state.view?.activeCollection;+ state.view?.type == "people" || state.view?.type == "album-overview"+ ? undefined+ : state.view?.activeCollection;const activeCollectionSummary =- state.view?.type == "people"+ state.view?.type == "people" || state.view?.type == "album-overview"? undefined: state.view?.activeCollectionSummary;const activePerson =@@ -547,6 +571,46 @@ const Page: React.FC = () => {? state.archivedCollectionSummaries: state.normalCollectionSummaries;+ const overviewAlbums = useMemo(() => {+ const sorted = sortCollectionSummaries(+ [...normalCollectionSummaries.values()].filter(+ (cs) => !cs.attributes.has("system"),+ ),+ collectionsSortBy,+ ).sort((a, b) => b.sortPriority - a.sortPriority);+ return filterAlbumSummaries(+ sorted,+ overviewFilter ?? albumFilter,+ albumSearchQuery,+ );+ }, [+ normalCollectionSummaries,+ collectionsSortBy,+ overviewFilter,+ albumFilter,+ albumSearchQuery,+ ]);++ useEffect(() => {+ if (barMode != "albums") setAlbumSearchQuery("");+ }, [barMode]);++ useEffect(() => {+ if (activeCollectionID == PseudoCollectionID.all)+ setAlbumSearchQuery("");+ }, [activeCollectionID]);++ useEffect(() => {+ if (!overviewFilter) return;+ const available = visibleAlbumFilters([+ ...normalCollectionSummaries.values(),+ ]);+ if (!available.some(({ value }) => value == overviewFilter)) {+ setAlbumFilter("ente");+ dispatch({ type: "showAlbumOverview", albumFilter: "ente" });+ }+ }, [normalCollectionSummaries, overviewFilter]);+const router = useRouter();useEffect(() => {@@ -666,17 +730,20 @@ const Page: React.FC = () => {}, [state.user, userDetails]);useEffect(() => {- if (typeof activeCollectionID == "undefined" || !router.isReady) {+ if (+ (!isAlbumOverview && typeof activeCollectionID == "undefined") ||+ !router.isReady+ ) {return;}let collectionURL = "";- if (activeCollectionID !== PseudoCollectionID.all) {+ if (!isAlbumOverview && activeCollectionID !== PseudoCollectionID.all) {// TODO: Is this URL param even used?collectionURL = `?collection=${activeCollectionID}`;}const href = `/gallery${collectionURL}`;void router.push(href, undefined, { shallow: true });- }, [activeCollectionID, router.isReady]);+ }, [activeCollectionID, isAlbumOverview, router.isReady]);useEffect(() => {if (!activeCollectionSummary) closeCollectionMap();@@ -1072,6 +1139,16 @@ const Page: React.FC = () => {? await createHiddenAlbum(name): await createAlbum(name);+ if (createForAlbumOverview.current) {+ await remotePull();+ showNotification({+ color: "primary",+ title: t("album_created"),+ });+ createForAlbumOverview.current = false;+ return;+ }+if (pendingSingleFileAdd.current) {await performCollectionOp("add",@@ -1107,7 +1184,7 @@ const Page: React.FC = () => {pendingSingleFileAdd.current = undefined;}},- [createOnSelectForCollectionOp, remotePull],+ [createOnSelectForCollectionOp, remotePull, showNotification],);const handleFavoriteFileOp = async (@@ -1509,12 +1586,19 @@ const Page: React.FC = () => {return true;};+ const handleShowAlbumOverview = (filter: AlbumFilter) => {+ setCleanupView(undefined);+ clearSelection();+ setAlbumFilter(filter);+ dispatch({ type: "showAlbumOverview", albumFilter: filter });+ };+const handleChangeBarMode = (mode: GalleryBarMode) => {if (mode == "people") {return handleShowPeople();}setCleanupView(undefined);- dispatch({ type: "showAlbums" });+ handleShowAlbumOverview("ente");return true;};@@ -2038,6 +2122,12 @@ const Page: React.FC = () => {activeCollection: activeCollection!,activeCollectionID: activeCollectionID!,activePerson,+ albumFilter,+ albumSearchQuery,+ onAlbumSearchQueryChange: setAlbumSearchQuery,+ onShowAlbumOverview: handleShowAlbumOverview,+ collectionsSortBy,+ onChangeCollectionsSortBy: setCollectionsSortBy,peopleSortBy,onChangePeopleSortBy: setPeopleSortBy,setFileListHeader,@@ -2130,6 +2220,23 @@ const Page: React.FC = () => {isUploadInProgress={uploadManager.isUploadInProgress()}onUpload={openUploader}/>+ ) : !isInSearchMode && !isFirstLoad && isAlbumOverview ? (+ <AlbumsOverview+ albums={overviewAlbums}+ title={(+ albumFilters.find(+ ({ value }) => value == overviewFilter,+ ) ?? albumFilters[0]!+ ).title()}+ filter={overviewFilter!}+ hasSearchQuery={!!albumSearchQuery.trim()}+ onSelectAlbum={handleShowCollectionSummaryWithID}+ onCreateAlbum={() => {+ createForAlbumOverview.current = true;+ postCreateAlbumHidden.current = false;+ showAlbumNameInput();+ }}+ />) : !isInSearchMode &&!isFirstLoad &&state.view?.type == "people" &&@@ -2320,6 +2427,7 @@ const Page: React.FC = () => {// Do not leak a cancelled add into the next album creation.pendingSingleFileAdd.current = undefined;postCreateAlbumHidden.current = false;+ createForAlbumOverview.current = false;albumNameInputVisibilityProps.onClose();}}onSubmit={handleAlbumNameSubmit}diff --git a/web/apps/photos/src/utils/album-filters.ts b/web/apps/photos/src/utils/album-filters.tsindex df768a7e17..d2b5e46b0e 100644--- a/web/apps/photos/src/utils/album-filters.ts+++ b/web/apps/photos/src/utils/album-filters.ts@@ -79,3 +79,18 @@ export const visibleAlbumFilters = (collectionSummaries: CollectionSummary[]) =>}return collectionSummaries.some((cs) => matchesAlbumFilter(cs, value));});++/** The sidebar and overview must display exactly the same album membership. */+export const filterAlbumSummaries = (+ summaries: CollectionSummary[],+ filter: AlbumFilter,+ query: string,+) => {+ const normalizedQuery = query.trim().toLowerCase();+ return summaries.filter(+ (cs) =>+ matchesAlbumFilter(cs, filter) &&+ (!normalizedQuery ||+ cs.name.toLowerCase().includes(normalizedQuery)),+ );+};diff --git a/web/apps/photos/src/utils/use-collections-sort.ts b/web/apps/photos/src/utils/use-collections-sort.tsnew file mode 100644index 0000000000..fb0d2bac3e--- /dev/null+++ b/web/apps/photos/src/utils/use-collections-sort.ts@@ -0,0 +1,26 @@+import {+ collectionsSortBy,+ type CollectionsSortBy,+} from "ente-new/photos/services/collection-summary";+import { includes } from "ente-utils/type-guards";+import { useEffect, useState } from "react";++export const useCollectionsSortByLocalState = (+ initialValue: CollectionsSortBy,+) => {+ const key = "collectionsSortBy";++ const [value, setValue] = useState(initialValue);++ useEffect(() => {+ const value = localStorage.getItem(key);+ if (value && includes(collectionsSortBy, value)) setValue(value);+ }, []);++ const setter = (value: CollectionsSortBy) => {+ localStorage.setItem(key, value);+ setValue(value);+ };++ return [value, setter] as const;+};diff --git a/web/apps/photos/tests/album-filters.test.ts b/web/apps/photos/tests/album-filters.test.tsindex 9952d7edde..570160f515 100644--- a/web/apps/photos/tests/album-filters.test.ts+++ b/web/apps/photos/tests/album-filters.test.ts@@ -4,6 +4,7 @@ import type {} from "ente-new/photos/services/collection-summary";import { describe, expect, test } from "vitest";import {+ filterAlbumSummaries,matchesAlbumFilter,visibleAlbumFilters,type AlbumFilter,@@ -137,3 +138,42 @@ describe("album filters shared by the dialog and sidebar", () => {]);});});++describe("album overview search", () => {+ test("combines group membership and a trimmed case-insensitive name query", () => {+ const owned = { ...album(1), name: "Summer holiday" };+ const shared = {+ ...album(2, ["sharedOutgoing"]),+ name: "SUMMER with friends",+ };+ const received = {+ ...album(3, ["sharedIncoming"]),+ name: "Summer wedding",+ };+ expect(+ filterAlbumSummaries(+ [owned, shared, received],+ "shared",+ " summer ",+ ),+ ).toEqual([shared]);+ expect(+ filterAlbumSummaries(+ [owned, shared, received],+ "received",+ "SUMMER",+ ),+ ).toEqual([received]);+ expect(+ filterAlbumSummaries([owned, shared], "ente", "missing"),+ ).toEqual([]);+ });++ test("preserves the caller's shared sort order and excludes archived albums", () => {+ const albums = [album(3), album(1), album(2, ["archived"])];+ expect(+ filterAlbumSummaries(albums, "ente", "").map(({ id }) => id),+ ).toEqual([3, 1]);+ expect(albums.map(({ id }) => id)).toEqual([3, 1, 2]);+ });+});diff --git a/web/apps/photos/tests/album-overview-navigation.test.ts b/web/apps/photos/tests/album-overview-navigation.test.tsnew file mode 100644index 0000000000..813f4bb4f8--- /dev/null+++ b/web/apps/photos/tests/album-overview-navigation.test.ts@@ -0,0 +1,118 @@+import type { LocalUser } from "ente-accounts/services/user";+import type { CollectionSummary } from "ente-new/photos/services/collection-summary";+import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";+import { describe, expect, test } from "vitest";+import {+ galleryReducer,+ initialGalleryState,+} from "../src/components/gallery/reducer";++const mounted = () =>+ galleryReducer(initialGalleryState, {+ type: "mount",+ user: { id: 1 } as LocalUser,+ familyData: undefined,+ collections: [],+ collectionFiles: [],+ trashItems: [],+ });++describe("album overview navigation", () => {+ test("opens a group without an active collection or stale photo search results", () => {+ const state = galleryReducer(+ {+ ...mounted(),+ isInSearchMode: true,+ isRecomputingSearchResults: true,+ },+ { type: "showAlbumOverview", albumFilter: "shared" },+ );+ expect(state.view).toEqual({+ type: "album-overview",+ albumFilter: "shared",+ });+ expect(state.selectedCollectionSummaryID).toBeUndefined();+ expect(state.filteredFiles).toEqual([]);+ expect(state.isInSearchMode).toBe(false);+ expect(state.isRecomputingSearchResults).toBe(false);+ expect(state.searchResults).toBeUndefined();+ });++ test("supports repeated group navigation, opening an album and returning Home", () => {+ const start = mounted();+ const favorite: CollectionSummary = {+ id: 10,+ type: "album",+ name: "Test album",+ fileCount: 0,+ attributes: new Set(),+ sortPriority: 0,+ coverFile: undefined,+ latestFile: undefined,+ updationTime: undefined,+ };+ start.normalCollectionSummaries.set(favorite.id, favorite);+ let state = galleryReducer(start, {+ type: "showAlbumOverview",+ albumFilter: "ente",+ });+ state = galleryReducer(state, {+ type: "showAlbumOverview",+ albumFilter: "received",+ });+ state = galleryReducer(state, {+ type: "showCollectionSummary",+ collectionSummaryID: favorite.id,+ });+ expect(state.view?.type).toBe("albums");+ expect(state.selectedCollectionSummaryID).toBe(favorite.id);+ state = galleryReducer(state, { type: "showAll" });+ expect(+ state.view?.type == "albums" &&+ state.view.activeCollectionSummaryID,+ ).toBe(PseudoCollectionID.all);+ });++ test("keeps the group overview through collection refreshes", () => {+ let state = galleryReducer(mounted(), {+ type: "showAlbumOverview",+ albumFilter: "ente",+ });+ state = galleryReducer(state, {+ type: "setCollections",+ collections: [],+ });+ state = galleryReducer(state, {+ type: "setCollectionFiles",+ collectionFiles: [],+ });+ state = galleryReducer(state, {+ type: "setTrashItems",+ trashItems: [],+ });+ state = galleryReducer(state, { type: "clearUnsyncedState" });+ expect(state.view).toEqual({+ type: "album-overview",+ albumFilter: "ente",+ });+ expect(state.filteredFiles).toEqual([]);+ });++ test("switches between the People overview and album groups", () => {+ let state = galleryReducer(mounted(), {+ type: "showAlbumOverview",+ albumFilter: "ente",+ });+ state = galleryReducer(state, { type: "showPeople" });+ expect(state.view?.type).toBe("people");+ state = galleryReducer(state, {+ type: "showAlbumOverview",+ albumFilter: "shared",+ });+ expect(state.view).toEqual({+ type: "album-overview",+ albumFilter: "shared",+ });+ expect(state.filteredFiles).toEqual([]);+ });+});diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.jsonindex fae3c176c2..48512b7320 100644--- a/web/packages/base/locales/en-US/translation.json+++ b/web/packages/base/locales/en-US/translation.json@@ -51,6 +51,12 @@"password_mismatch_error": "Passwords don't match","show_or_hide_password": "Show or hide password","welcome_to_ente_title": "Welcome to <a/>",+ "album_overview_shared_title": "Shared by you",+ "album_overview_received_title": "Shared with you",+ "album_overview_count_one": "{{count, number}} album",+ "album_overview_count_other": "{{count, number}} albums",+ "album_items_count_one": "{{count, number}} item",+ "album_items_count_other": "{{count, number}} items","new_album": "New album","create_albums": "Create albums","album_name": "Album name",