Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[photos] Add standalone album cover picker

AswinAsok63846c1b9fed
diff --git a/web/apps/photos/public/images/cover-selected.svg b/web/apps/photos/public/images/cover-selected.svg
new file mode 100644
index 0000000000..cbb965e6c3
--- /dev/null
+++ b/web/apps/photos/public/images/cover-selected.svg
@@ -0,0 +1,5 @@
+<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="13" height="13" viewBox="0 0 13 13" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="Frame">
+<path id="Vector" d="M2.16667 6.77083L5.14583 9.75L10.8333 3.52083" stroke-width="1.625" stroke-linecap="round" stroke-linejoin="round" stroke="white" style="stroke:white;stroke-opacity:1;"/>
+</g>
+</svg>
diff --git a/web/apps/photos/src/components/collections/CoverPhotoGrid.tsx b/web/apps/photos/src/components/collections/CoverPhotoGrid.tsx
new file mode 100644
index 0000000000..daff80c02b
--- /dev/null
+++ b/web/apps/photos/src/components/collections/CoverPhotoGrid.tsx
@@ -0,0 +1,264 @@
+import { Box, styled } from "@mui/material";
+import log from "ente-base/log";
+import { downloadManager } from "ente-gallery/services/download";
+import type { EnteFile } from "ente-media/file";
+import {
+ LoadingThumbnail,
+ StaticThumbnail,
+} from "ente-new/photos/components/PlaceholderThumbnails";
+import { BaseTileButton } from "ente-new/photos/components/Tiles";
+import { t } from "i18next";
+import { memo, useEffect, useId, useMemo, useState } from "react";
+import {
+ areEqual,
+ FixedSizeList,
+ type ListChildComponentProps,
+} from "react-window";
+
+interface CoverPhotoGridProps {
+ width: number;
+ height: number;
+ photos: EnteFile[];
+ selectedFileID: number | undefined;
+ currentCoverID: number | undefined;
+ disabled: boolean;
+ onSelect: (fileID: number) => void;
+}
+
+const tileSize = 148;
+const gap = 10;
+const padding = 24;
+
+/** A virtualized, single-selection grid without the gallery's interactions. */
+export const CoverPhotoGrid = ({
+ width,
+ height,
+ photos,
+ selectedFileID,
+ currentCoverID,
+ disabled,
+ onSelect,
+}: CoverPhotoGridProps) => {
+ const availableWidth = Math.max(1, width - 2 * padding);
+ const columns = Math.min(
+ 4,
+ Math.max(1, Math.floor((availableWidth + gap) / (tileSize + gap))),
+ );
+ const size = Math.min(tileSize, availableWidth);
+ const itemData = useMemo(
+ () => ({
+ photos,
+ selectedFileID,
+ currentCoverID,
+ disabled,
+ onSelect,
+ columns,
+ size,
+ }),
+ [
+ photos,
+ selectedFileID,
+ currentCoverID,
+ disabled,
+ onSelect,
+ columns,
+ size,
+ ],
+ );
+
+ return (
+ <FixedSizeList
+ width={width}
+ height={height}
+ itemCount={Math.ceil(photos.length / columns)}
+ itemSize={size + gap}
+ itemData={itemData}
+ overscanCount={2}
+ useIsScrolling
+ >
+ {CoverPhotoRow}
+ </FixedSizeList>
+ );
+};
+
+type RowData = Omit<CoverPhotoGridProps, "width" | "height"> & {
+ columns: number;
+ size: number;
+};
+
+const CoverPhotoRow = memo(
+ ({ index, style, isScrolling, data }: ListChildComponentProps<RowData>) => {
+ const {
+ photos,
+ columns,
+ size,
+ selectedFileID,
+ currentCoverID,
+ disabled,
+ onSelect,
+ } = data;
+ return (
+ <Box
+ style={style}
+ sx={{
+ display: "flex",
+ gap: `${gap}px`,
+ px: `${padding}px`,
+ boxSizing: "border-box",
+ }}
+ >
+ {photos
+ .slice(index * columns, (index + 1) * columns)
+ .map((file) => (
+ <CoverPhotoCard
+ key={file.id}
+ file={file}
+ size={size}
+ isScrolling={Boolean(isScrolling)}
+ selected={file.id === selectedFileID}
+ current={file.id === currentCoverID}
+ disabled={disabled}
+ onSelect={onSelect}
+ />
+ ))}
+ </Box>
+ );
+ },
+ areEqual,
+);
+
+interface CoverPhotoCardProps {
+ file: EnteFile;
+ size: number;
+ isScrolling: boolean;
+ selected: boolean;
+ current: boolean;
+ disabled: boolean;
+ onSelect: (fileID: number) => void;
+}
+
+const CoverPhotoCard = ({
+ file,
+ size,
+ isScrolling,
+ selected,
+ current,
+ disabled,
+ onSelect,
+}: CoverPhotoCardProps) => {
+ const currentLabelID = useId();
+ const [thumbnail, setThumbnail] = useState<{
+ fileID: number;
+ url: string;
+ }>();
+ const [failedFileID, setFailedFileID] = useState<number>();
+ const imageURL = thumbnail?.fileID === file.id ? thumbnail.url : undefined;
+
+ useEffect(() => {
+ if (file.metadata.hasStaticThumbnail) return;
+ let cancelled = false;
+ void downloadManager
+ .renderableThumbnailURL(file, isScrolling)
+ .then((url) => {
+ if (!cancelled && url) {
+ setFailedFileID(undefined);
+ setThumbnail({ fileID: file.id, url });
+ }
+ })
+ .catch((error: unknown) => {
+ if (!cancelled) {
+ setFailedFileID(file.id);
+ log.warn("Failed to fetch cover thumbnail", error);
+ }
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [file, isScrolling]);
+
+ return (
+ <PhotoButton
+ type="button"
+ aria-label={file.metadata.title}
+ aria-pressed={selected}
+ aria-describedby={current ? currentLabelID : undefined}
+ disabled={disabled}
+ onClick={() => onSelect(file.id)}
+ sx={{ width: size, height: size }}
+ >
+ {file.metadata.hasStaticThumbnail || failedFileID === file.id ? (
+ <StaticThumbnail fileType={file.metadata.fileType} />
+ ) : imageURL ? (
+ <img src={imageURL} alt="" />
+ ) : (
+ <LoadingThumbnail />
+ )}
+ {selected && (
+ <Box
+ sx={{
+ position: "absolute",
+ inset: 0,
+ border: "3px solid #08c225",
+ borderRadius: "inherit",
+ pointerEvents: "none",
+ }}
+ >
+ <Box
+ sx={{
+ position: "absolute",
+ top: 7,
+ right: 7,
+ width: 26,
+ height: 26,
+ boxSizing: "border-box",
+ borderRadius: "50%",
+ bgcolor: "#08c225",
+ border: "2px solid #fff",
+ display: "grid",
+ placeItems: "center",
+ }}
+ >
+ <img
+ src="/images/cover-selected.svg"
+ width={13}
+ height={13}
+ alt=""
+ />
+ </Box>
+ </Box>
+ )}
+ {current && (
+ <Box
+ id={currentLabelID}
+ sx={{
+ position: "absolute",
+ bottom: 10,
+ left: 10,
+ px: "11px",
+ py: "4px",
+ borderRadius: "10px",
+ bgcolor: "rgba(0 0 0 / 0.55)",
+ color: "#fff",
+ fontSize: 10,
+ fontWeight: 500,
+ lineHeight: "12px",
+ pointerEvents: "none",
+ }}
+ >
+ {t("current_cover")}
+ </Box>
+ )}
+ </PhotoButton>
+ );
+};
+
+const PhotoButton = styled(BaseTileButton)({
+ flexShrink: 0,
+ borderRadius: "12px",
+ "& > div": { borderRadius: "inherit" },
+ "&:focus-visible": {
+ outline: "2px solid currentColor",
+ outlineOffset: "-5px",
+ },
+ "&:disabled": { cursor: "default" },
+});
diff --git a/web/apps/photos/src/components/collections/CoverPickerDialog.tsx b/web/apps/photos/src/components/collections/CoverPickerDialog.tsx
new file mode 100644
index 0000000000..a28e441f80
--- /dev/null
+++ b/web/apps/photos/src/components/collections/CoverPickerDialog.tsx
@@ -0,0 +1,291 @@
+import { Cancel01Icon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import {
+ Box,
+ Dialog,
+ IconButton,
+ Stack,
+ Typography,
+ type Theme,
+} from "@mui/material";
+import { LoadingButton } from "ente-base/components/mui/LoadingButton";
+import {
+ v2CancelButtonSx,
+ v2SubmitButtonSx,
+} from "ente-base/components/SingleInput.styles";
+import {
+ uploadSheetMediaQuery,
+ uploadSheetPaperSx,
+ useIsUploadSheet,
+} from "ente-gallery/components/upload-progress/bottom-sheet";
+import type { Collection } from "ente-media/collection";
+import type { EnteFile } from "ente-media/file";
+import { FileType } from "ente-media/file-type";
+import { SlideUpTransition } from "ente-new/photos/components/mui/SlideUpTransition";
+import { t } from "i18next";
+import React, { useCallback, useEffect, useId, useMemo, useState } from "react";
+import AutoSizer from "react-virtualized-auto-sizer";
+import { CoverPhotoGrid } from "./CoverPhotoGrid";
+
+interface CoverPickerDialogProps {
+ open: boolean;
+ onClose: () => void;
+ collection: Collection;
+ files: EnteFile[];
+ currentCoverFile: EnteFile | undefined;
+ canResetToDefault: boolean;
+ onUseSelectedPhoto: (file: EnteFile) => Promise<boolean>;
+ onResetToDefault: () => Promise<boolean>;
+}
+
+type SubmittingAction = "use-selected-photo" | "reset-to-default";
+
+export const CoverPickerDialog: React.FC<CoverPickerDialogProps> = ({
+ open,
+ onClose,
+ collection,
+ files,
+ currentCoverFile,
+ canResetToDefault,
+ onUseSelectedPhoto,
+ onResetToDefault,
+}) => {
+ const isSheet = useIsUploadSheet();
+ const titleID = useId();
+ const descriptionID = useId();
+ const [submittingAction, setSubmittingAction] = useState<
+ SubmittingAction | undefined
+ >();
+ const [selectedFileID, setSelectedFileID] = useState<number>();
+ const isSubmitting = Boolean(submittingAction);
+ const currentCoverID = currentCoverFile?.id;
+
+ const photos = useMemo(() => {
+ const eligible = files.filter(
+ (file) => file.metadata.fileType !== FileType.video,
+ );
+ const currentIndex = eligible.findIndex(
+ ({ id }) => id === currentCoverID,
+ );
+ if (currentIndex > 0)
+ eligible.unshift(...eligible.splice(currentIndex, 1));
+ return eligible;
+ }, [files, currentCoverID]);
+
+ useEffect(() => {
+ if (open) {
+ setSelectedFileID(currentCoverID);
+ setSubmittingAction(undefined);
+ }
+ }, [open, collection.id, currentCoverID]);
+
+ const selectedFile = photos.find(({ id }) => id === selectedFileID);
+
+ const handleUseSelectedPhoto = useCallback(async () => {
+ if (!selectedFile || isSubmitting) return;
+
+ setSubmittingAction("use-selected-photo");
+ try {
+ const didUpdate = await onUseSelectedPhoto(selectedFile);
+ if (didUpdate) onClose();
+ } finally {
+ setSubmittingAction(undefined);
+ }
+ }, [onUseSelectedPhoto, onClose, selectedFile, isSubmitting]);
+
+ const handleResetToDefault = useCallback(async () => {
+ if (isSubmitting) return;
+ setSubmittingAction("reset-to-default");
+ try {
+ const didReset = await onResetToDefault();
+ if (didReset) onClose();
+ } finally {
+ setSubmittingAction(undefined);
+ }
+ }, [onResetToDefault, onClose, isSubmitting]);
+
+ return (
+ <Dialog
+ open={open}
+ onClose={isSubmitting ? undefined : onClose}
+ aria-labelledby={titleID}
+ aria-describedby={descriptionID}
+ maxWidth={false}
+ slots={isSheet ? { transition: SlideUpTransition } : undefined}
+ slotProps={{ paper: { sx: [paperSx, uploadSheetPaperSx] } }}
+ >
+ <Stack
+ sx={{ height: "100%", minHeight: 0 }}
+ aria-busy={isSubmitting}
+ >
+ <Stack direction="row" sx={headerSx}>
+ <Stack sx={{ minWidth: 0, gap: "2px" }}>
+ <Typography id={titleID} sx={titleSx}>
+ {t("choose_cover")}
+ </Typography>
+ <Typography id={descriptionID} sx={subtitleSx}>
+ {t("pick_cover_from_album", {
+ album: collection.name,
+ })}
+ </Typography>
+ </Stack>
+ <IconButton
+ aria-label={t("close")}
+ onClick={onClose}
+ disabled={isSubmitting}
+ sx={closeButtonSx}
+ >
+ <HugeiconsIcon icon={Cancel01Icon} size={16} />
+ </IconButton>
+ </Stack>
+ <Box sx={{ flex: 1, minHeight: 0, py: "18px" }}>
+ {photos.length ? (
+ <AutoSizer>
+ {({ width, height }) =>
+ width > 0 && height > 0 ? (
+ <CoverPhotoGrid
+ {...{
+ width,
+ height,
+ photos,
+ selectedFileID,
+ currentCoverID,
+ }}
+ disabled={isSubmitting}
+ onSelect={setSelectedFileID}
+ />
+ ) : (
+ <></>
+ )
+ }
+ </AutoSizer>
+ ) : (
+ <Typography sx={{ color: "text.muted", px: "24px" }}>
+ {t("no_photos_found_here")}
+ </Typography>
+ )}
+ </Box>
+ <Stack sx={footerSx}>
+ <LoadingButton
+ fullWidth
+ color="accent"
+ onClick={handleUseSelectedPhoto}
+ loading={submittingAction === "use-selected-photo"}
+ disabled={
+ !selectedFile ||
+ (isSubmitting &&
+ submittingAction !== "use-selected-photo")
+ }
+ sx={[
+ v2SubmitButtonSx,
+ actionButtonSx,
+ ...(submittingAction === "use-selected-photo"
+ ? []
+ : [primaryButtonDisabledSx]),
+ ]}
+ >
+ {t("set_as_cover")}
+ </LoadingButton>
+ {canResetToDefault && (
+ <LoadingButton
+ fullWidth
+ color="secondary"
+ onClick={handleResetToDefault}
+ loading={submittingAction === "reset-to-default"}
+ disabled={
+ isSubmitting &&
+ submittingAction !== "reset-to-default"
+ }
+ sx={[
+ v2CancelButtonSx,
+ actionButtonSx,
+ secondaryButtonSx,
+ ]}
+ >
+ {t("reset_to_default")}
+ </LoadingButton>
+ )}
+ </Stack>
+ </Stack>
+ </Dialog>
+ );
+};
+
+const paperSx = {
+ width: "min(688px, calc(100svw - 32px))",
+ maxWidth: "688px",
+ height: "560px",
+ maxHeight: "calc(100dvh - 32px)",
+ boxSizing: "border-box",
+ m: 2,
+ borderRadius: "20px",
+ backgroundColor: "background.paper",
+ backgroundImage: "none",
+ boxShadow: "0px 24px 64px rgba(0 0 0 / 0.28)",
+};
+const headerSx = {
+ alignItems: "center",
+ justifyContent: "space-between",
+ gap: "12px",
+ p: "20px 20px 16px 24px",
+ borderBottom: "1px solid",
+ borderColor: "stroke.fainter",
+ flexShrink: 0,
+};
+const titleSx = { fontSize: 18, lineHeight: "24px", fontWeight: 600 };
+const subtitleSx = {
+ fontSize: 12,
+ lineHeight: "16px",
+ fontWeight: 500,
+ color: "text.muted",
+ overflowWrap: "anywhere",
+};
+const closeButtonSx = {
+ width: 24,
+ height: 24,
+ p: 0,
+ flexShrink: 0,
+ color: "text.muted",
+};
+const footerSx = (theme: Theme) => ({
+ gap: "12px",
+ px: "24px",
+ py: "14px",
+ flexShrink: 0,
+ borderTop: "1px solid",
+ borderColor: "stroke.fainter",
+ backgroundColor: "#f4f4f4",
+ ...theme.applyStyles("dark", { backgroundColor: "#1b1b1b" }),
+ [uploadSheetMediaQuery]: {
+ px: "16px",
+ pb: "calc(14px + env(safe-area-inset-bottom, 0px))",
+ },
+});
+const actionButtonSx = {
+ flex: "none",
+ minHeight: 52,
+ px: "24px",
+ py: "14px",
+ textTransform: "none",
+ boxShadow: "none",
+ "&:hover": { boxShadow: "none" },
+};
+const secondaryButtonSx = (theme: Theme) => ({
+ "&:hover": { backgroundColor: "#e0e0e0" },
+ "&.Mui-disabled": { opacity: 1 },
+ ...theme.applyStyles("dark", {
+ backgroundColor: "#282828",
+ "&:hover": { backgroundColor: "#333" },
+ }),
+});
+const primaryButtonDisabledSx = (theme: Theme) => ({
+ "&.Mui-disabled": {
+ opacity: 1,
+ color: "#d6d6d6",
+ backgroundColor: "#eaeaea",
+ ...theme.applyStyles("dark", {
+ color: "rgba(255 255 255 / 0.3)",
+ backgroundColor: "rgba(255 255 255 / 0.12)",
+ }),
+ },
+});
diff --git a/web/apps/photos/src/components/collections/EditAlbumDetailsDialog.tsx b/web/apps/photos/src/components/collections/EditAlbumDetailsDialog.tsx
index ee465e9e74..310aaa7abe 100644
--- a/web/apps/photos/src/components/collections/EditAlbumDetailsDialog.tsx
+++ b/web/apps/photos/src/components/collections/EditAlbumDetailsDialog.tsx
@@ -12,7 +12,6 @@ import {
type SxProps,
type Theme,
} from "@mui/material";
-import type { LocalUser } from "ente-accounts/services/user";
import { LoadingButton } from "ente-base/components/mui/LoadingButton";
import {
useModalVisibility,
@@ -38,7 +37,7 @@ import { albumDescriptionGraphemeCount } from "ente-new/photos/services/collecti
import { useFormik } from "formik";
import { t } from "i18next";
import React, { useId, useState } from "react";
-import { PickCoverPhotoDialog } from "./PickCoverPhotoDialog";
+import { CoverPickerDialog } from "./CoverPickerDialog";
export interface AlbumDetails {
name: string;
@@ -50,7 +49,6 @@ type EditAlbumDetailsDialogProps = ModalVisibilityProps & {
collection: Collection;
files: EnteFile[];
initialCoverFile: EnteFile | undefined;
- user: LocalUser;
onSubmit: (details: AlbumDetails) => Promise<void>;
};
@@ -60,7 +58,6 @@ export const EditAlbumDetailsDialog: React.FC<EditAlbumDetailsDialogProps> = ({
collection,
files,
initialCoverFile,
- user,
onSubmit,
}) => {
const { showMiniDialog, onGenericError } = useBaseContext();
@@ -281,11 +278,11 @@ export const EditAlbumDetailsDialog: React.FC<EditAlbumDetailsDialogProps> = ({
</Stack>
</Dialog>
{canShowCoverEditor && (
- <PickCoverPhotoDialog
+ <CoverPickerDialog
{...pickCoverPhotoVisibilityProps}
collection={collection}
files={files}
- user={user}
+ currentCoverFile={effectiveCoverFile}
canResetToDefault={effectiveCoverID > 0}
onUseSelectedPhoto={handleUseSelectedPhoto}
onResetToDefault={handleResetToDefault}
diff --git a/web/apps/photos/src/components/collections/PickCoverPhotoDialog.tsx b/web/apps/photos/src/components/collections/PickCoverPhotoDialog.tsx
deleted file mode 100644
index 0ce003645b..0000000000
--- a/web/apps/photos/src/components/collections/PickCoverPhotoDialog.tsx
+++ /dev/null
@@ -1,329 +0,0 @@
-import { fileTimelineDateString, type SelectedState } from "@/utils/file";
-import { ArrowLeft02Icon, Cancel01Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
-import {
- Box,
- Dialog,
- IconButton,
- Stack,
- Typography,
- type Theme,
-} from "@mui/material";
-import type { LocalUser } from "ente-accounts/services/user";
-import { LoadingButton } from "ente-base/components/mui/LoadingButton";
-import {
- v2CancelButtonSx,
- v2CloseButtonSx,
- v2PaperSx,
- v2SubmitButtonSx,
- v2TitleSx,
-} from "ente-base/components/SingleInput.styles";
-import { isSxArray } from "ente-base/components/utils/sx";
-import {
- uploadSheetMediaQuery,
- uploadSheetPaperSx,
- useIsUploadSheet,
-} from "ente-gallery/components/upload-progress/bottom-sheet";
-import type { Collection } from "ente-media/collection";
-import type { EnteFile } from "ente-media/file";
-import { FileType } from "ente-media/file-type";
-import { SlideUpTransition } from "ente-new/photos/components/mui/SlideUpTransition";
-import { t } from "i18next";
-import React, { useCallback, useEffect, useId, useMemo, useState } from "react";
-import AutoSizer from "react-virtualized-auto-sizer";
-import { FileList, type FileListAnnotatedFile } from "../FileList";
-
-interface PickCoverPhotoDialogProps {
- open: boolean;
- onClose: () => void;
- collection: Collection;
- files: EnteFile[];
- user: LocalUser;
- canResetToDefault: boolean;
- onUseSelectedPhoto: (file: EnteFile) => Promise<boolean>;
- onResetToDefault: () => Promise<boolean>;
-}
-
-type SubmittingAction = "use-selected-photo" | "reset-to-default";
-
-export const PickCoverPhotoDialog: React.FC<PickCoverPhotoDialogProps> = ({
- open,
- onClose,
- collection,
- files,
- user,
- canResetToDefault,
- onUseSelectedPhoto,
- onResetToDefault,
-}) => {
- const isSheet = useIsUploadSheet();
- const titleID = useId();
- const [submittingAction, setSubmittingAction] = useState<
- SubmittingAction | undefined
- >();
- const [selected, setSelected] = useState<SelectedState>(
- createEmptySelection(collection.id),
- );
- const isSubmitting = Boolean(submittingAction);
-
- useEffect(() => {
- if (open) {
- setSelected(createEmptySelection(collection.id));
- setSubmittingAction(undefined);
- }
- }, [open, collection.id]);
-
- const annotatedFiles = useMemo((): FileListAnnotatedFile[] => {
- if (!open) return [];
-
- return files
- .filter((file) => file.metadata.fileType !== FileType.video)
- .map((file) => ({
- file,
- timelineDateString: fileTimelineDateString(file),
- }));
- }, [open, files]);
-
- const selectedFile = useMemo(() => {
- if (!open) return undefined;
-
- for (const [key, value] of Object.entries(selected)) {
- if (typeof value !== "boolean" || !value) continue;
- const selectedFileID = Number(key);
- return files.find(({ id }) => id === selectedFileID);
- }
- return undefined;
- }, [open, selected, files]);
-
- const handleItemClick = useCallback(
- (index: number) => {
- const file = annotatedFiles[index]?.file;
- if (!file) return;
- setSelected(createSingleSelection(file, collection.id, user.id));
- },
- [annotatedFiles, collection.id, user.id],
- );
-
- const handleUseSelectedPhoto = useCallback(async () => {
- if (!selectedFile) return;
-
- setSubmittingAction("use-selected-photo");
- try {
- const didUpdate = await onUseSelectedPhoto(selectedFile);
- if (didUpdate) onClose();
- } finally {
- setSubmittingAction(undefined);
- }
- }, [onUseSelectedPhoto, onClose, selectedFile]);
-
- const handleResetToDefault = useCallback(async () => {
- setSubmittingAction("reset-to-default");
- try {
- const didReset = await onResetToDefault();
- if (didReset) onClose();
- } finally {
- setSubmittingAction(undefined);
- }
- }, [onResetToDefault, onClose]);
-
- return (
- <Dialog
- open={open}
- onClose={isSubmitting ? undefined : onClose}
- aria-labelledby={titleID}
- maxWidth={false}
- slots={isSheet ? { transition: SlideUpTransition } : undefined}
- slotProps={{
- paper: {
- sx: [
- ...(isSxArray(v2PaperSx) ? v2PaperSx : [v2PaperSx]),
- paperSx,
- uploadSheetPaperSx,
- ],
- },
- }}
- >
- <Stack sx={contentSx} aria-busy={isSubmitting}>
- <Stack
- direction="row"
- sx={{ alignItems: "center", gap: "8px" }}
- >
- <IconButton
- aria-label={t("go_back")}
- onClick={onClose}
- disabled={isSubmitting}
- sx={backButtonSx}
- >
- <HugeiconsIcon icon={ArrowLeft02Icon} size={24} />
- </IconButton>
- <Typography id={titleID} sx={[v2TitleSx, titleSx]}>
- {t("choose_cover")}
- </Typography>
- <IconButton
- aria-label={t("close")}
- onClick={onClose}
- disabled={isSubmitting}
- sx={v2CloseButtonSx}
- >
- <HugeiconsIcon icon={Cancel01Icon} size={18} />
- </IconButton>
- </Stack>
- <Stack sx={{ flex: 1, minHeight: 0, gap: "24px" }}>
- <Box sx={{ flex: 1, minHeight: 0 }}>
- {annotatedFiles.length ? (
- <AutoSizer>
- {({ width, height }) =>
- width > 0 && height > 0 ? (
- <FileList
- {...{
- width,
- height,
- user,
- annotatedFiles,
- selected,
- setSelected,
- }}
- mode="albums"
- enableSelect={false}
- activeCollectionID={collection.id}
- onItemClick={handleItemClick}
- disableGrouping
- />
- ) : (
- <></>
- )
- }
- </AutoSizer>
- ) : (
- <Typography sx={{ color: "text.muted" }}>
- {t("no_photos_found_here")}
- </Typography>
- )}
- </Box>
- <Stack sx={{ gap: "12px", flexShrink: 0 }}>
- <LoadingButton
- fullWidth
- color="accent"
- onClick={handleUseSelectedPhoto}
- loading={submittingAction === "use-selected-photo"}
- disabled={
- !selectedFile ||
- (isSubmitting &&
- submittingAction !== "use-selected-photo")
- }
- autoFocus={Boolean(selectedFile)}
- sx={[
- v2SubmitButtonSx,
- actionButtonSx,
- ...(submittingAction === "use-selected-photo"
- ? []
- : [primaryButtonDisabledSx]),
- ]}
- >
- {t("set_as_cover")}
- </LoadingButton>
- {canResetToDefault && (
- <LoadingButton
- fullWidth
- color="secondary"
- onClick={handleResetToDefault}
- loading={
- submittingAction === "reset-to-default"
- }
- disabled={
- isSubmitting &&
- submittingAction !== "reset-to-default"
- }
- sx={[
- v2CancelButtonSx,
- actionButtonSx,
- secondaryButtonSx,
- ]}
- >
- {t("reset_to_default")}
- </LoadingButton>
- )}
- </Stack>
- </Stack>
- </Stack>
- </Dialog>
- );
-};
-
-const createEmptySelection = (collectionID: number): SelectedState => ({
- ownCount: 0,
- count: 0,
- collectionID,
- context: { mode: "albums", collectionID },
-});
-
-const createSingleSelection = (
- file: EnteFile,
- collectionID: number,
- userID: number,
-): SelectedState => ({
- [file.id]: true,
- ownCount: file.ownerID === userID ? 1 : 0,
- count: 1,
- collectionID,
- context: { mode: "albums", collectionID },
-});
-
-const paperSx = {
- width: "min(714px, calc(100svw - 32px))",
- maxWidth: "714px",
- height: "656px",
- maxHeight: "calc(100dvh - 32px)",
- boxSizing: "border-box",
-};
-const contentSx = {
- p: "20px",
- gap: "36px",
- height: "100%",
- minHeight: 0,
- [uploadSheetMediaQuery]: {
- p: "12px 16px",
- pb: "calc(20px + env(safe-area-inset-bottom, 0px))",
- },
-};
-const titleSx = {
- flex: 1,
- minWidth: 0,
- fontFamily: "'Outfit Variable', sans-serif",
- overflowWrap: "anywhere",
-};
-const backButtonSx = {
- width: 38,
- height: 38,
- p: 0,
- flexShrink: 0,
- color: "text.base",
-};
-const actionButtonSx = {
- flex: "none",
- minHeight: 52,
- px: "24px",
- py: "14px",
- textTransform: "none",
- boxShadow: "none",
- "&:hover": { boxShadow: "none" },
-};
-const primaryButtonDisabledSx = (theme: Theme) => ({
- "&.Mui-disabled": {
- opacity: 1,
- color: "#d6d6d6",
- backgroundColor: "#eaeaea",
- ...theme.applyStyles("dark", {
- color: "rgba(255 255 255 / 0.3)",
- backgroundColor: "rgba(255 255 255 / 0.12)",
- }),
- },
-});
-const secondaryButtonSx = (theme: Theme) => ({
- "&:hover": { backgroundColor: "#e0e0e0" },
- "&.Mui-disabled": { opacity: 1 },
- ...theme.applyStyles("dark", {
- backgroundColor: "#282828",
- "&:hover": { backgroundColor: "#333" },
- }),
-});
diff --git a/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx b/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx
index ab7b20346e..7ec4a78c76 100644
--- a/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx
+++ b/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx
@@ -1,5 +1,5 @@
import { ManagePublicShareOptions } from "@/components/collections/CollectionShare";
-import { PickCoverPhotoDialog } from "@/components/collections/PickCoverPhotoDialog";
+import { CoverPickerDialog } from "@/components/collections/CoverPickerDialog";
import { usePublicLinkURL } from "@/components/utils/use-public-link-url";
import { Copy01Icon, Edit03Icon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
@@ -270,11 +270,11 @@ export const PublicLinkDetails = ({
)}
</Stack>
{canChangeCover && pickCoverPhotoVisibilityProps.open && (
- <PickCoverPhotoDialog
+ <CoverPickerDialog
{...pickCoverPhotoVisibilityProps}
collection={collection}
files={files}
- user={user}
+ currentCoverFile={coverFile}
canResetToDefault={
(collection.pubMagicMetadata?.data.coverID ?? 0) > 0
}
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 3271ff0bd0..628c9c84e5 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -2528,7 +2528,6 @@ const Page: React.FC = () => {
collection={activeCollection}
files={activeCollectionFiles}
initialCoverFile={activeCollectionSummary?.coverFile}
- user={user}
onSubmit={handleEditAlbumDetails}
/>
)}
diff --git a/web/apps/photos/tests/cover-photo-grid.test.tsx b/web/apps/photos/tests/cover-photo-grid.test.tsx
new file mode 100644
index 0000000000..23e04a2a44
--- /dev/null
+++ b/web/apps/photos/tests/cover-photo-grid.test.tsx
@@ -0,0 +1,79 @@
+import { ThemeProvider } from "@mui/material";
+import { photosTheme } from "ente-base/components/utils/theme";
+import type { EnteFile } from "ente-media/file";
+import { FileType } from "ente-media/file-type";
+import type { ComponentProps } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { describe, expect, test, vi } from "vitest";
+import { CoverPhotoGrid } from "../src/components/collections/CoverPhotoGrid";
+
+vi.mock("ente-gallery/services/download", () => ({ downloadManager: {} }));
+vi.mock("ente-new/photos/services/ml", () => ({ faceCrop: vi.fn() }));
+vi.mock("i18next", () => ({ t: () => "Current" }));
+
+const photo = (id: number) =>
+ ({
+ id,
+ metadata: {
+ title: `Photo ${id}`,
+ fileType: FileType.image,
+ hasStaticThumbnail: true,
+ },
+ }) as EnteFile;
+
+const renderGrid = (
+ overrides: Partial<ComponentProps<typeof CoverPhotoGrid>> = {},
+) =>
+ renderToStaticMarkup(
+ <ThemeProvider theme={photosTheme}>
+ <CoverPhotoGrid
+ width={720}
+ height={366}
+ photos={Array.from({ length: 10000 }, (_, i) => photo(i))}
+ currentCoverID={0}
+ selectedFileID={1}
+ disabled={false}
+ onSelect={vi.fn()}
+ {...overrides}
+ />
+ </ThemeProvider>,
+ );
+
+describe("cover photo grid", () => {
+ test("mounts a bounded window of a large album", () => {
+ const markup = renderGrid();
+ const cards = markup.match(/<button\b[^>]*aria-pressed=/g) ?? [];
+ expect(cards.length).toBeGreaterThan(0);
+ expect(cards.length).toBeLessThan(32);
+ expect(markup).toContain('aria-label="Photo 0"');
+ expect(markup).not.toContain('aria-label="Photo 9999"');
+ });
+
+ test("marks the selection separately from the current cover", () => {
+ const markup = renderGrid({ photos: [photo(0), photo(1)] });
+ expect(markup).toMatch(
+ /aria-label="Photo 0" aria-pressed="false" aria-describedby=/,
+ );
+ expect(markup).toMatch(/aria-label="Photo 1" aria-pressed="true"/);
+ expect(markup.match(/>Current</g)).toHaveLength(1);
+ expect(
+ markup.match(/src="\/images\/cover-selected.svg"/g),
+ ).toHaveLength(1);
+ });
+
+ test("disables every visible card during submission", () => {
+ const markup = renderGrid({
+ photos: [photo(0), photo(1)],
+ disabled: true,
+ });
+ const cards = markup.match(/<button\b[^>]*>/g) ?? [];
+ expect(cards).toHaveLength(2);
+ for (const card of cards) expect(card).toContain('disabled=""');
+ });
+
+ test("supports a narrow viewport and an empty album", () => {
+ const markup = renderGrid({ width: 220, photos: [photo(0), photo(1)] });
+ expect(markup).toContain('aria-label="Photo 1"');
+ expect(renderGrid({ photos: [] })).not.toContain("aria-pressed=");
+ });
+});
diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.json
index 31c68e203e..cc5c687223 100644
--- a/web/packages/base/locales/en-US/translation.json
+++ b/web/packages/base/locales/en-US/translation.json
@@ -465,6 +465,8 @@
"album_cover": "Album cover",
"set_cover": "Set cover",
"choose_cover": "Choose cover",
+ "pick_cover_from_album": "Pick any photo from {{album}}",
+ "current_cover": "Current",
"set_as_cover": "Set as cover",
"select_cover_photo": "Select cover photo",
"reset_to_default": "Reset to default",