π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[web][photos] Add covers to album and people headers
AswinAsok3f2d40ba3d63
diff --git a/web/apps/photos/src/components/collections/CollectionHeader.tsx b/web/apps/photos/src/components/collections/CollectionHeader.tsxindex 84b294cb71..72be662205 100644--- a/web/apps/photos/src/components/collections/CollectionHeader.tsx+++ b/web/apps/photos/src/components/collections/CollectionHeader.tsx@@ -42,9 +42,12 @@ import {import type { CollectionSortBy } from "ente-media/collection-sort";import { ItemVisibility } from "ente-media/file-metadata";import {+ AlbumDescription,+ GalleryItemsCoverTile,GalleryItemsHeaderAdapter,GalleryItemsSummary,} from "ente-new/photos/components/gallery/ListHeader";+import { ItemCard } from "ente-new/photos/components/Tiles";import {cleanUncategorized,defaultHiddenCollectionUserFacingName,@@ -70,7 +73,7 @@ import {import { emptyTrash } from "ente-new/photos/services/trash";import { usePhotosAppContext } from "ente-new/photos/types/context";import { t } from "i18next";-import React, { useCallback, useRef, useState } from "react";+import React, { useCallback, useEffect, useRef, useState } from "react";import { Trans } from "react-i18next";export interface CollectionHeaderProps {@@ -88,14 +91,27 @@ export interface CollectionHeaderProps {onAddSaveGroup: AddSaveGroup;onShowMap: () => void;onBackToAlbums: () => void;- onDescriptionHeightChange?: (height: number) => void;+ onHeightChange?: (height: number) => void;}export const CollectionHeader: React.FC<CollectionHeaderProps> = (props) => {- const { activeCollection, collectionSummary, onDescriptionHeightChange } =- props;+ const { activeCollection, collectionSummary, onHeightChange } = props;+ const headerRef = useRef<HTMLDivElement>(null);++ useEffect(() => {+ const header = headerRef.current;+ if (!header || !onHeightChange) return;+ // Include the adapter's bottom margin in the virtualized header height.+ const report = () =>+ onHeightChange(Math.max(72, header.offsetHeight + 12));+ report();+ const observer = new ResizeObserver(report);+ observer.observe(header);+ return () => observer.disconnect();+ }, [onHeightChange]);const { name, type, attributes, fileCount } = collectionSummary;+ const isAlbum = isAlbumSummary(collectionSummary);const description =activeCollection?.pubMagicMetadata?.data.caption?.trim();@@ -121,11 +137,17 @@ export const CollectionHeader: React.FC<CollectionHeaderProps> = (props) => {};return (- <GalleryItemsHeaderAdapter>- <SpacedRow>+ <GalleryItemsHeaderAdapter ref={headerRef}>+ <SpacedRow+ sx={{ gap: 2, alignItems: isAlbum ? "flex-start" : "center" }}+ ><Stackdirection="row"- sx={{ gap: 1, alignItems: "center", minWidth: 0 }}+ sx={{+ gap: isAlbum ? 2 : 1,+ alignItems: "center",+ minWidth: 0,+ }}>{(type == "hiddenItems" || type == "archiveItems") && (<Tooltip title={t("go_back")}>@@ -138,23 +160,44 @@ export const CollectionHeader: React.FC<CollectionHeaderProps> = (props) => {</IconButton></Tooltip>)}+ {isAlbum && (+ <ItemCard+ key={`${collectionSummary.id}-${collectionSummary.coverFile?.id ?? "empty"}`}+ TileComponent={GalleryItemsCoverTile}+ coverFile={collectionSummary.coverFile}+ />+ )}<GalleryItemsSummary+ compact={isAlbum}+ nameProps={+ isAlbum+ ? { sx: { overflowWrap: "anywhere" } }+ : undefined+ }name={name}- description={description}+ description={isAlbum ? undefined : description}descriptionMaxWidth={480}fileCount={fileCount}endIcon={<EndIcon />}- onDescriptionHeightChange={onDescriptionHeightChange}/></Stack>{shouldShowOptions(type) && (<CollectionHeaderOptions {...props} />)}</SpacedRow>+ {isAlbum && (+ <AlbumDescription+ description={description}+ sx={{ pt: 1, maxWidth: 480, color: "text.faint" }}+ />+ )}</GalleryItemsHeaderAdapter>);};+const isAlbumSummary = ({ type }: CollectionSummary) =>+ type == "album" || type == "folder" || type == "sharedIncoming";+const shouldShowOptions = (type: CollectionSummaryType) =>type != "all" && type != "archiveItems";@@ -645,7 +688,14 @@ const CollectionHeaderOptions: React.FC<CollectionHeaderProps> = ({const validMenuOptions = menuOptions.filter((o) => !!o);return (- <Box sx={{ display: "inline-flex", gap: "16px" }}>+ <Box+ sx={{+ display: "inline-flex",+ gap: "16px",+ flexShrink: 0,+ mt: isAlbumSummary(collectionSummary) ? "3px" : 0,+ }}+ ><QuickOptionscollectionSummary={collectionSummary}isQuickLinkAlbum={isQuickLinkAlbum}@@ -665,6 +715,7 @@ const CollectionHeaderOptions: React.FC<CollectionHeaderProps> = ({{validMenuOptions.length > 0 && (<><IconButton+ aria-label={t("more_options")}id="collection-options-trigger"aria-controls={menuAnchorEl ? "collection-options" : undefineddiff --git a/web/apps/photos/src/components/collections/GalleryBarAndListHeader.tsx b/web/apps/photos/src/components/collections/GalleryBarAndListHeader.tsxindex bc0ede89f6..6b18031a01 100644--- a/web/apps/photos/src/components/collections/GalleryBarAndListHeader.tsx+++ b/web/apps/photos/src/components/collections/GalleryBarAndListHeader.tsx@@ -98,9 +98,7 @@ export const GalleryBarAndListHeader: React.FC<collectionShareVisibilityProps.onClose();}, [collectionShareVisibilityProps]);- const albumDescription =- activeCollection?.pubMagicMetadata?.data.caption?.trim();- const [descriptionHeight, setDescriptionHeight] = useState(0);+ const [headerHeight, setHeaderHeight] = useState(72);useEffect(() => {if (shouldHide || mode == "links") return;@@ -131,7 +129,7 @@ export const GalleryBarAndListHeader: React.FC<onCollectionCast={showCollectionCast}onEditAlbumDetails={onEditAlbumDetails}hasActiveFileSelection={hasActiveFileSelection}- onDescriptionHeightChange={setDescriptionHeight}+ onHeightChange={setHeaderHeight}/>) : mode != "people" && collectionSummary ? (<GalleryItemsHeaderAdapter>@@ -143,13 +141,17 @@ export const GalleryBarAndListHeader: React.FC<) : activePerson ? (<PeopleHeaderperson={activePerson}+ onHeightChange={setHeaderHeight}people={people}onSelectPerson={onSelectPerson}/>) : (<></>),- height: 72 + (albumDescription ? descriptionHeight : 0),+ height:+ shouldRenderCollectionHeader || activePerson+ ? headerHeight+ : 72,});// eslint-disable-next-line react-hooks/exhaustive-deps}, [@@ -170,8 +172,7 @@ export const GalleryBarAndListHeader: React.FC<onCollectionSlideshow,onBackToAlbums,onEditAlbumDetails,- albumDescription,- descriptionHeight,+ headerHeight,// TODO: Cluster// This causes a loop since it is an array dep// people,diff --git a/web/apps/photos/src/components/gallery/PeopleHeader.tsx b/web/apps/photos/src/components/gallery/PeopleHeader.tsxindex 72302c7333..dbfff7caab 100644--- a/web/apps/photos/src/components/gallery/PeopleHeader.tsx+++ b/web/apps/photos/src/components/gallery/PeopleHeader.tsx@@ -47,6 +47,7 @@ import {import { useBaseContext } from "ente-base/context";import log from "ente-base/log";import {+ GalleryItemsCoverTile,GalleryItemsHeaderAdapter,GalleryItemsSummary,} from "ente-new/photos/components/gallery/ListHeader";@@ -78,22 +79,35 @@ import type {PreviewableCluster,} from "ente-new/photos/services/ml/people";import { t } from "i18next";-import React, { useEffect, useReducer, useState } from "react";+import React, { useEffect, useReducer, useRef, useState } from "react";import type { GalleryBarImplProps } from "./BarImpl";type PeopleHeaderProps = Pick<GalleryBarImplProps,"people" | "onSelectPerson"-> & { person: Person };+> & { person: Person; onHeightChange?: (height: number) => void };export const PeopleHeader: React.FC<PeopleHeaderProps> = ({people,onSelectPerson,person,+ onHeightChange,}) => {+ const headerRef = useRef<HTMLDivElement>(null);+ useEffect(() => {+ const header = headerRef.current;+ if (!header || !onHeightChange) return;+ const report = () =>+ onHeightChange(Math.max(72, header.offsetHeight + 12));+ report();+ const observer = new ResizeObserver(report);+ observer.observe(header);+ return () => observer.disconnect();+ }, [onHeightChange]);+return (- <GalleryItemsHeaderAdapter>- <SpacedRow>+ <GalleryItemsHeaderAdapter ref={headerRef}>+ <SpacedRow sx={{ gap: 2 }}>{person.type == "cgroup" ? (person.isHidden ? (<IgnoredPersonHeader person={person} />@@ -111,6 +125,32 @@ export const PeopleHeader: React.FC<PeopleHeaderProps> = ({);};+const PersonHeaderSummary = ({+ person,+ ...summaryProps+}: { person: Person } & Pick<+ React.ComponentProps<typeof GalleryItemsSummary>,+ "name" | "nameProps" | "onNameClick"+>) => (+ <Stack direction="row" sx={{ gap: 2, alignItems: "center", minWidth: 0 }}>+ <ItemCard+ key={`${person.id}-${person.displayFaceID}`}+ TileComponent={GalleryItemsCoverTile}+ coverFile={person.displayFaceFile}+ coverFaceID={person.displayFaceID}+ />+ <GalleryItemsSummary+ {...summaryProps}+ compact+ fileCount={person.fileIDs.length}+ nameProps={{+ ...summaryProps.nameProps,+ sx: { overflowWrap: "anywhere" },+ }}+ />+ </Stack>+);+interface CGroupPersonHeaderProps {person: CGroupPerson;}@@ -141,14 +181,12 @@ const CGroupPersonHeader: React.FC<CGroupPersonHeaderProps> = ({ person }) => {});// This view only receives unignored, named people.- const name = cgroup.data.name ?? "";+ const name =+ person.name?.trim() || cgroup.data.name?.trim() || t("unnamed_person");return (<>- <GalleryItemsSummary- name={name}- fileCount={person.fileIDs.length}- />+ <PersonHeaderSummary person={person} name={name} /><OverflowMenu ariaID="person-options"><OverflowMenuOptionstartIcon={<ListAltOutlinedIcon />}@@ -216,10 +254,10 @@ const IgnoredPersonHeader: React.FC<IgnoredPersonHeaderProps> = ({return (<>- <GalleryItemsSummary- name={t("ignored")}+ <PersonHeaderSummary+ person={person}+ name={person.name?.trim() || t("ignored")}nameProps={{ color: "text.muted" }}- fileCount={person.fileIDs.length}/><OverflowMenu ariaID="person-options"><OverflowMenuOption@@ -263,10 +301,10 @@ const ClusterPersonHeader: React.FC<ClusterPersonHeaderProps> = ({return (<>- <GalleryItemsSummary- name={t("unnamed_person")}+ <PersonHeaderSummary+ person={person}+ name={person.name?.trim() || t("unnamed_person")}nameProps={{ color: "text.muted" }}- fileCount={person.fileIDs.length}onNameClick={showAddPerson}/><Stack direction="row" sx={{ alignItems: "center", gap: 2 }}>diff --git a/web/packages/new/photos/components/gallery/ListHeader.tsx b/web/packages/new/photos/components/gallery/ListHeader.tsxindex c4f0b0bc94..0248988955 100644--- a/web/packages/new/photos/components/gallery/ListHeader.tsx+++ b/web/packages/new/photos/components/gallery/ListHeader.tsx@@ -11,6 +11,7 @@ import React, { useEffect, useRef, useState } from "react";interface GalleryItemsSummaryProps {name: string;+ compact?: boolean;description?: string;descriptionMaxWidth?: number;nameProps?: TypographyProps;@@ -23,6 +24,7 @@ interface GalleryItemsSummaryProps {export const GalleryItemsSummary: React.FC<GalleryItemsSummaryProps> = ({name,+ compact = false,description,descriptionMaxWidth,nameProps,@@ -58,8 +60,8 @@ export const GalleryItemsSummary: React.FC<GalleryItemsSummaryProps> = ({sx={{gap: 1.5,// Keep the header height stable without an end icon.- minHeight: "24px",- mt: "4px",+ minHeight: compact ? "20px" : "24px",+ mt: compact ? "2px" : "4px",}}><Typography@@ -68,7 +70,7 @@ export const GalleryItemsSummary: React.FC<GalleryItemsSummaryProps> = ({color: "text.muted",fontSize: "14px",fontWeight: 500,- lineHeight: "18px",+ lineHeight: compact ? "20px" : "18px",}}>{t("photos_count", { count: fileCount })}@@ -164,3 +166,15 @@ export const GalleryItemsHeaderAdapter = styled("div")`width: 100%;margin-bottom: 12px;`;++/** A compact cover shared by album and person gallery headers. */+export const GalleryItemsCoverTile = styled("div")({+ width: 54,+ height: 54,+ flexShrink: 0,+ borderRadius: 12,+ overflow: "hidden",+ position: "relative",+ alignSelf: "flex-start",+ "& > img": { width: "100%", height: "100%", objectFit: "cover" },+});