Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat(gallery):adding-notification-toast

Aswin Asoke936d39185d9
diff --git a/web/apps/photos/src/components/AddToAlbumProgress.tsx b/web/apps/photos/src/components/AddToAlbumProgress.tsx
new file mode 100644
index 0000000000..44233442e9
--- /dev/null
+++ b/web/apps/photos/src/components/AddToAlbumProgress.tsx
@@ -0,0 +1,99 @@
+// TODO: Review AddToAlbumProgress for accessibility and consistent UI patterns.
+import ArrowForwardIcon from "@mui/icons-material/ArrowForward";
+import CloseIcon from "@mui/icons-material/Close";
+import {
+ Box,
+ DialogTitle,
+ Paper,
+ Snackbar,
+ Stack,
+ Typography,
+} from "@mui/material";
+import { FilledIconButton } from "ente-base/components/mui";
+import { t } from "i18next";
+import React from "react";
+
+export type AddToAlbumPhase = "processing" | "done" | "failed";
+
+interface AddToAlbumProgressProps {
+ open: boolean;
+ onClose: () => void;
+ phase: AddToAlbumPhase;
+ /** The file name to show as subtitle (truncated). */
+ fileName?: string;
+ /** Called when the arrow CTA is clicked to navigate to the album. */
+ onArrowClick?: () => void;
+}
+
+/**
+ * Minimal progress UI for add-to-album operations.
+ */
+export const AddToAlbumProgress: React.FC<AddToAlbumProgressProps> = ({
+ open,
+ onClose,
+ phase,
+ fileName,
+ onArrowClick,
+}) => {
+ // Only show the toast once the operation completes successfully.
+ const shouldShow = open && phase === "done";
+
+ return (
+ <Snackbar
+ open={shouldShow}
+ anchorOrigin={{ horizontal: "right", vertical: "bottom" }}
+ >
+ <Paper sx={{ width: "min(360px, 100svw)" }}>
+ <DialogTitle>
+ <Stack
+ direction="row"
+ sx={{
+ justifyContent: "space-between",
+ alignItems: "center",
+ }}
+ >
+ <Box>
+ <Typography variant="h3">
+ {/* Intentionally using a simple title for clarity */}
+ {t("add_to_album")}
+ </Typography>
+ {fileName && (
+ <Typography
+ variant="body"
+ sx={{
+ fontWeight: "regular",
+ color: "text.muted",
+ marginTop: "4px",
+ }}
+ >
+ {truncate(fileName, 15)}
+ </Typography>
+ )}
+ </Box>
+ <Stack direction="row" sx={{ gap: 1 }}>
+ {onArrowClick && (
+ <FilledIconButton
+ onClick={() => {
+ onArrowClick();
+ onClose();
+ }}
+ >
+ <ArrowForwardIcon />
+ </FilledIconButton>
+ )}
+ <FilledIconButton
+ onClick={onClose}
+ aria-label={t("close")}
+ >
+ <CloseIcon />
+ </FilledIconButton>
+ </Stack>
+ </Stack>
+ </DialogTitle>
+ </Paper>
+ </Snackbar>
+ );
+};
+
+const truncate = (s: string, max: number) =>
+ s.length > max ? `${s.substring(0, max)}...` : s;
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 2df4eb319a..f66616a712 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -6,6 +6,8 @@ import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import FileUploadOutlinedIcon from "@mui/icons-material/FileUploadOutlined";
import MenuIcon from "@mui/icons-material/Menu";
import { IconButton, Link, Stack, Typography } from "@mui/material";
+import type { AddToAlbumPhase } from "components/AddToAlbumProgress";
+import { AddToAlbumProgress } from "components/AddToAlbumProgress";
import { AuthenticateUser } from "components/AuthenticateUser";
import { GalleryBarAndListHeader } from "components/Collections/GalleryBarAndListHeader";
import { DownloadStatusNotifications } from "components/DownloadStatusNotifications";
@@ -45,6 +47,7 @@ import { type UploadTypeSelectorIntent } from "ente-gallery/components/Upload";
import { useSaveGroups } from "ente-gallery/components/utils/save-groups";
import { type Collection } from "ente-media/collection";
import { type EnteFile } from "ente-media/file";
+import { fileFileName } from "ente-media/file-metadata";
import { type ItemVisibility } from "ente-media/file-metadata";
import {
CollectionSelector,
@@ -237,6 +240,14 @@ const Page: React.FC = () => {
const { show: showAlbumNameInput, props: albumNameInputVisibilityProps } =
useModalVisibility();
+ // Progress UI state for single-file add-to-album from the FileViewer
+ const [addToAlbumProgress, setAddToAlbumProgress] = useState<{
+ open: boolean;
+ phase: AddToAlbumPhase;
+ albumId?: number;
+ fileName?: string;
+ }>({ open: false, phase: "processing" });
+
const onAuthenticateCallback = useRef<(() => void) | undefined>(undefined);
const authenticateUser = useCallback(
@@ -1028,8 +1039,16 @@ const Page: React.FC = () => {
sourceCollectionSummaryID,
);
await remotePull({ silent: true });
+ // Show custom toast with file name and navigation
+ setAddToAlbumProgress({
+ open: true,
+ phase: "done",
+ albumId: collection.id,
+ fileName: fileFileName(file),
+ });
} catch (e) {
onGenericError(e);
+ // Do not show the toast on failure; handled by generic error notification
} finally {
pendingSingleFileAdd.current = undefined;
hideLoadingBar();
@@ -1304,6 +1323,19 @@ const Page: React.FC = () => {
}}
onSubmit={handleAlbumNameSubmit}
/>
+ <AddToAlbumProgress
+ open={addToAlbumProgress.open}
+ onClose={() =>
+ setAddToAlbumProgress((s) => ({ ...s, open: false }))
+ }
+ phase={addToAlbumProgress.phase}
+ fileName={addToAlbumProgress.fileName}
+ onArrowClick={() => {
+ if (addToAlbumProgress.albumId !== undefined) {
+ handleSelectCollection(addToAlbumProgress.albumId);
+ }
+ }}
+ />
</FullScreenDropZone>
);
};
diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.json
index a3e05d8cf9..2528d919e8 100644
--- a/web/packages/base/locales/en-US/translation.json
+++ b/web/packages/base/locales/en-US/translation.json
@@ -687,6 +687,7 @@
"person_favorites": "{{name}}'s favorites",
"shared_favorites": "Shared favorites",
"added_by_name": "Added by {{name}}",
+ "added": "{{count, number}} added",
"unowned_files_not_processed": "Files added by other users were not processed",
"custom_domains": "Custom domains",
"custom_domains_desc": "Use your own domain when sharing",