π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[web] Match empty album confirmation to gallery dialog
AswinAsok90eed86ef5ed
diff --git a/web/apps/photos/src/components/Collections/AllAlbums.tsx b/web/apps/photos/src/components/Collections/AllAlbums.tsxindex 876257fdfe..872009ec0e 100644--- a/web/apps/photos/src/components/Collections/AllAlbums.tsx+++ b/web/apps/photos/src/components/Collections/AllAlbums.tsx@@ -1,3 +1,4 @@+import { TrashFilesDialog } from "@/components/gallery/TrashFilesDialog";// TODO: Audit this file.import {CreateAlbumTile,@@ -104,8 +105,11 @@ export const AllAlbums: React.FC<AllAlbums> = ({onClose();};- const { handleDeleteEmptyAlbums, hasEnoughEmptyAlbums } =- useDeleteEmptyAlbums(collectionSummaries, onRemotePull);+ const {+ handleDeleteEmptyAlbums,+ hasEnoughEmptyAlbums,+ deleteEmptyAlbumsDialogProps,+ } = useDeleteEmptyAlbums(collectionSummaries, onRemotePull);const showDeleteEmptyAlbums =showAlbumFilters &&@@ -250,6 +254,7 @@ export const AllAlbums: React.FC<AllAlbums> = ({</Box>)}</Dialog>+ <TrashFilesDialog {...deleteEmptyAlbumsDialogProps} /></>);};diff --git a/web/apps/photos/src/components/Collections/useDeleteEmptyAlbums.ts b/web/apps/photos/src/components/Collections/useDeleteEmptyAlbums.tsindex a08a0c90da..b7707e4a7a 100644--- a/web/apps/photos/src/components/Collections/useDeleteEmptyAlbums.ts+++ b/web/apps/photos/src/components/Collections/useDeleteEmptyAlbums.ts@@ -1,6 +1,5 @@import type { RemotePullOpts } from "@/components/gallery";import { ensureLocalUser } from "ente-accounts/services/user";-import { useBaseContext } from "ente-base/context";import {deleteCollection,isArchivedCollection,@@ -16,12 +15,13 @@ import {} from "ente-new/photos/services/photos-fdb";import { usePhotosAppContext } from "ente-new/photos/types/context";import { t } from "i18next";+import { useState } from "react";export const useDeleteEmptyAlbums = (collectionSummaries: CollectionSummary[],onRemotePull: (opts?: RemotePullOpts) => Promise<void>,) => {- const { showMiniDialog } = useBaseContext();+ const [candidateIDs, setCandidateIDs] = useState<number[]>();const { showNotification } = usePhotosAppContext();const emptyAlbumCandidates = collectionSummaries.filter(isBulkDeletableEmptyAlbum,@@ -98,22 +98,22 @@ export const useDeleteEmptyAlbums = (};const handleDeleteEmptyAlbums = () => {- const candidateIDs = emptyAlbumCandidates.map((cs) => cs.id);- showMiniDialog({- title: t("delete_empty_albums_title"),- message: t("delete_empty_albums_message", {- count: candidateIDs.length,- }),- continue: {- text: t("delete"),- color: "critical",- action: () => deleteEmptyAlbums(candidateIDs),- },- });+ setCandidateIDs(emptyAlbumCandidates.map((cs) => cs.id));};return {handleDeleteEmptyAlbums,+ deleteEmptyAlbumsDialogProps: {+ open: candidateIDs !== undefined,+ onClose: () => setCandidateIDs(undefined),+ count: candidateIDs?.length ?? 0,+ title: t("delete_empty_albums_title"),+ message: t("delete_empty_albums_message", {+ count: candidateIDs?.length ?? 0,+ }),+ confirmText: t("delete"),+ onConfirm: () => deleteEmptyAlbums(candidateIDs ?? []),+ },hasEnoughEmptyAlbums: emptyAlbumCandidates.length >= 3,};};diff --git a/web/apps/photos/src/components/gallery/AlbumsOverview.tsx b/web/apps/photos/src/components/gallery/AlbumsOverview.tsxindex 3e05a71e9c..60e3801984 100644--- a/web/apps/photos/src/components/gallery/AlbumsOverview.tsx+++ b/web/apps/photos/src/components/gallery/AlbumsOverview.tsx@@ -1,5 +1,6 @@import { useDeleteEmptyAlbums } from "@/components/Collections/useDeleteEmptyAlbums";import type { RemotePullOpts } from "@/components/gallery";+import { TrashFilesDialog } from "@/components/gallery/TrashFilesDialog";import type { AlbumFilter } from "@/utils/album-filters";import { Delete02Icon } from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";@@ -63,8 +64,11 @@ export const AlbumsOverview = ({return () => observer.disconnect();}, [listElement]);const normalizedSearchQuery = searchQuery.trim().toLowerCase();- const { handleDeleteEmptyAlbums, hasEnoughEmptyAlbums } =- useDeleteEmptyAlbums(albums, onRemotePull);+ const {+ handleDeleteEmptyAlbums,+ hasEnoughEmptyAlbums,+ deleteEmptyAlbumsDialogProps,+ } = useDeleteEmptyAlbums(albums, onRemotePull);const showDeleteEmptyAlbums =filter == "empty-albums" &&hasEnoughEmptyAlbums &&@@ -86,123 +90,133 @@ export const AlbumsOverview = ({}, [filter, normalizedSearchQuery, sortBy]);return (- <Stack- sx={{- flex: 1,- minHeight: 0,- overflow: "hidden",- px: { xs: "14px", md: "24px" },- pb: { xs: "16px", md: "36px" },- gap: "24px",- }}- >+ <>+ <TrashFilesDialog {...deleteEmptyAlbumsDialogProps} /><Stacksx={{- flexShrink: 0,- minHeight: 54,- flexDirection: "row",- alignItems: "center",- justifyContent: "space-between",- flexWrap: "wrap",- gap: 2,+ flex: 1,+ minHeight: 0,+ overflow: "hidden",+ px: { xs: "14px", md: "24px" },+ pb: { xs: "16px", md: "36px" },+ gap: "24px",}}>- <Stack sx={{ minWidth: 0, gap: "2px" }}>+ <Stack+ sx={{+ flexShrink: 0,+ minHeight: 54,+ flexDirection: "row",+ alignItems: "center",+ justifyContent: "space-between",+ flexWrap: "wrap",+ gap: 2,+ }}+ >+ <Stack sx={{ minWidth: 0, 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>+ {showDeleteEmptyAlbums && (+ <Tooltip title={t("delete_empty_albums")}>+ <IconButton+ aria-label={t("delete_empty_albums")}+ onClick={handleDeleteEmptyAlbums}+ sx={{+ flexShrink: 0,+ marginInlineStart: "auto",+ }}+ >+ <HugeiconsIcon+ icon={Delete02Icon}+ size={22}+ strokeWidth={1.5}+ />+ </IconButton>+ </Tooltip>+ )}+ </Stack>+ {!albums.length && !showCreate ? (<Typography- component="h1"- sx={{- fontFamily: '"Outfit Variable", Outfit, sans-serif',- fontSize: { xs: 20, md: 24 },- lineHeight: { xs: "26px", md: "32px" },- fontWeight: 600,- }}+ role="status"+ sx={{ color: "text.muted", fontSize: 14 }}>- {displayTitle}+ {t("no_results")}</Typography>- <Typography+ ) : (+ <Boxsx={{- fontSize: { xs: 12, md: 14 },- lineHeight: "20px",- color: "text.muted",+ flex: 1,+ minHeight: 0,+ "--album-tile-width": `${tileWidth}px`,+ "--album-name-size": compact ? "13px" : "14px",+ "--album-count-size": compact ? "11px" : "12px",}}>- {t("album_overview_count", { count: albums.length })}- </Typography>- </Stack>- {showDeleteEmptyAlbums && (- <Tooltip title={t("delete_empty_albums")}>- <IconButton- aria-label={t("delete_empty_albums")}- onClick={handleDeleteEmptyAlbums}- sx={{ flexShrink: 0, marginInlineStart: "auto" }}- >- <HugeiconsIcon- icon={Delete02Icon}- size={22}- strokeWidth={1.5}- />- </IconButton>- </Tooltip>+ <AutoSizer>+ {({ width, height }) => {+ 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>- {!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 }) => {- 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>+ </>);};diff --git a/web/apps/photos/src/components/gallery/TrashFilesDialog.tsx b/web/apps/photos/src/components/gallery/TrashFilesDialog.tsxindex 9e43f8d46a..162dd0397e 100644--- a/web/apps/photos/src/components/gallery/TrashFilesDialog.tsx+++ b/web/apps/photos/src/components/gallery/TrashFilesDialog.tsx@@ -18,6 +18,9 @@ import { useId, useState } from "react";type TrashFilesDialogProps = ModalVisibilityProps & {count: number;+ title?: string;+ message?: string;+ confirmText?: string;onConfirm: () => void | Promise<void>;};@@ -25,6 +28,9 @@ export const TrashFilesDialog: React.FC<TrashFilesDialogProps> = ({open,onClose,count,+ title,+ message,+ confirmText,onConfirm,}) => {const [phase, setPhase] = useState<"loading" | "failed" | undefined>();@@ -101,28 +107,30 @@ export const TrashFilesDialog: React.FC<TrashFilesDialogProps> = ({id={titleID}sx={{ "&&&": { p: 0, mt: 3 }, fontSize: 20 }}>- {t("trash_items_title", {- count,- fallbackLng: false,- defaultValue: t(- count === 1- ? "trash_file_title"- : "trash_files_title",- ),- })}+ {title ??+ t("trash_items_title", {+ count,+ fallbackLng: false,+ defaultValue: t(+ count === 1+ ? "trash_file_title"+ : "trash_files_title",+ ),+ })}</DialogTitle></Stack><DialogContent sx={{ padding: "16px 28px 24px" }}><Typography id={messageID} sx={{ color: "text.muted" }}>- {t("trash_items_message", {- count,- fallbackLng: false,- defaultValue: t(- count === 1- ? "trash_file_message"- : "trash_files_message",- ),- })}+ {message ??+ t("trash_items_message", {+ count,+ fallbackLng: false,+ defaultValue: t(+ count === 1+ ? "trash_file_message"+ : "trash_files_message",+ ),+ })}</Typography><Stack sx={{ pt: 3, gap: 1 }}>{phase === "failed" && <InlineErrorIndicator />}@@ -132,7 +140,7 @@ export const TrashFilesDialog: React.FC<TrashFilesDialogProps> = ({color="critical"onClick={handleConfirm}>- {t("move_to_trash")}+ {confirmText ?? t("move_to_trash")}</LoadingButton><FocusVisibleButtonfullWidthdiff --git a/web/apps/photos/tests/delete-empty-albums.test.ts b/web/apps/photos/tests/delete-empty-albums.test.tsindex 6ae20d3b90..0f39dc3e31 100644--- a/web/apps/photos/tests/delete-empty-albums.test.ts+++ b/web/apps/photos/tests/delete-empty-albums.test.ts@@ -3,12 +3,7 @@ import { beforeEach, describe, expect, test, vi } from "vitest";import { useDeleteEmptyAlbums } from "../src/components/Collections/useDeleteEmptyAlbums";const mocks = vi.hoisted(() => ({- dialog: vi.fn<- (dialog: {- message: unknown;- continue: { action: () => Promise<void> };- }) => void- >(),+ candidateIDs: undefined as number[] | undefined,notify: vi.fn<(notification: { title: { key: string; opts?: unknown } }) => void>(),@@ -17,8 +12,13 @@ const mocks = vi.hoisted(() => ({files: vi.fn(),remove: vi.fn(),}));-vi.mock("ente-base/context", () => ({- useBaseContext: () => ({ showMiniDialog: mocks.dialog }),+vi.mock("react", () => ({+ useState: () => [+ mocks.candidateIDs,+ (ids: number[] | undefined) => {+ mocks.candidateIDs = ids;+ },+ ],}));vi.mock("ente-new/photos/types/context", () => ({usePhotosAppContext: () => ({ showNotification: mocks.notify }),@@ -60,10 +60,12 @@ const collection = (id: number) => ({const start = (ids = [1, 2, 3]) => {const result = useDeleteEmptyAlbums(ids.map(summary), mocks.pull);result.handleDeleteEmptyAlbums();- return mocks.dialog.mock.calls[0]![0];+ return useDeleteEmptyAlbums(ids.map(summary), mocks.pull)+ .deleteEmptyAlbumsDialogProps;};beforeEach(() => {vi.resetAllMocks();+ mocks.candidateIDs = undefined;mocks.pull.mockResolvedValue(undefined);mocks.collections.mockResolvedValue([1, 2, 3].map(collection));mocks.files.mockResolvedValue([]);@@ -72,12 +74,19 @@ beforeEach(() => {describe("shared empty album deletion", () => {test("confirms the candidate count and does nothing until confirmed", () => {const dialog = start();+ expect(dialog.open).toBe(true);+ expect(dialog.count).toBe(3);expect(dialog.message).toEqual({key: "delete_empty_albums_message",opts: { count: 3 },});expect(mocks.pull).not.toHaveBeenCalled();expect(mocks.remove).not.toHaveBeenCalled();+ dialog.onClose();+ expect(+ useDeleteEmptyAlbums([summary(1)], mocks.pull)+ .deleteEmptyAlbumsDialogProps.open,+ ).toBe(false);expect(useDeleteEmptyAlbums([summary(1), summary(2)], mocks.pull).hasEnoughEmptyAlbums,@@ -96,7 +105,7 @@ describe("shared empty album deletion", () => {collection(9),]);mocks.files.mockResolvedValue([{ collectionID: 2 }]);- await start([1, 2, 3, 4, 5, 6, 7, 8]).continue.action();+ await start([1, 2, 3, 4, 5, 6, 7, 8]).onConfirm();expect(mocks.remove.mock.calls).toEqual([[1, { keepFiles: true }]]);expect(mocks.pull.mock.calls).toEqual([[{ strict: true }],@@ -105,7 +114,7 @@ describe("shared empty album deletion", () => {});test("aborts on initial sync failure", async () => {mocks.pull.mockRejectedValueOnce(new Error("sync"));- await start().continue.action();+ await start().onConfirm();expect(mocks.remove).not.toHaveBeenCalled();expect(mocks.notify.mock.calls[0]![0].title).toEqual({key: "delete_empty_albums_failed",@@ -114,7 +123,7 @@ describe("shared empty album deletion", () => {});test("continues after a deletion failure and reports the failed count", async () => {mocks.remove.mockRejectedValueOnce(new Error("delete"));- await start().continue.action();+ await start().onConfirm();expect(mocks.remove).toHaveBeenCalledTimes(3);expect(mocks.pull).toHaveBeenCalledTimes(2);expect(mocks.notify.mock.calls[0]![0].title).toEqual({@@ -126,7 +135,7 @@ describe("shared empty album deletion", () => {mocks.pull.mockResolvedValueOnce(undefined).mockRejectedValueOnce(new Error("refresh"));- await start().continue.action();+ await start().onConfirm();expect(mocks.notify.mock.calls[0]![0].title.key).toBe("delete_empty_albums_refresh_failed",);