Skip to content

armgit / ente

Public Imported from GitHub
0

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

fix(DownloadStatusNotification):single-file-notification-auto-close

Aswin Asokef8e4bff16fc
diff --git a/web/apps/photos/src/components/DownloadStatusNotifications.tsx b/web/apps/photos/src/components/DownloadStatusNotifications.tsx
index a5487a3c48..4e6f3defa0 100644
--- a/web/apps/photos/src/components/DownloadStatusNotifications.tsx
+++ b/web/apps/photos/src/components/DownloadStatusNotifications.tsx
@@ -26,6 +26,7 @@ import { useState } from "react";
/** Maximum characters for album name before truncation */
const MAX_ALBUM_NAME_LENGTH = 25;
+const SINGLE_FILE_SUCCESS_AUTO_CLOSE_DELAY_MS = 3000;
/** Truncate album name with ellipsis if it exceeds max length */
const truncateAlbumName = (name: string): string => {
@@ -146,6 +147,8 @@ export const DownloadStatusNotifications: React.FC<
const hasErrors = isSaveCompleteWithErrors(group);
const isComplete = isSaveComplete(group);
const canRetry = hasErrors && !!group.retry;
+ const shouldAutoClose =
+ group.total === 1 && isComplete && !hasErrors;
// Determine if this is a ZIP download (web with multiple files or live photo)
const isZipDownload = !group.downloadDirPath && group.total > 1;
@@ -289,6 +292,11 @@ export const DownloadStatusNotifications: React.FC<
})}
open={true}
onClose={createOnClose(group)}
+ autoHideDuration={
+ shouldAutoClose
+ ? SINGLE_FILE_SUCCESS_AUTO_CLOSE_DELAY_MS
+ : undefined
+ }
keepOpenOnClick
attributes={{
color: hasErrors ? "critical" : "secondary",
diff --git a/web/packages/new/photos/components/Notification.tsx b/web/packages/new/photos/components/Notification.tsx
index c9b44ef8ca..7e4f199052 100644
--- a/web/packages/new/photos/components/Notification.tsx
+++ b/web/packages/new/photos/components/Notification.tsx
@@ -72,10 +72,6 @@ export interface NotificationAttributes {
* notification body.
*/
onEndIconClick?: () => void;
- /**
- * If set, the notification will automatically close after this many
- * milliseconds.
- */
}
type NotificationProps = ModalVisibilityProps & {
@@ -101,6 +97,10 @@ type NotificationProps = ModalVisibilityProps & {
* Default: "bottom".
*/
vertical?: "top" | "bottom";
+ /**
+ * Optional time in milliseconds after which the notification closes.
+ */
+ autoHideDuration?: number;
/**
* sx props to customize the appearance of the underlying MUI
* {@link Snackbar}.
@@ -125,6 +125,7 @@ export const Notification: React.FC<NotificationProps> = ({
onClose,
horizontal,
vertical,
+ autoHideDuration,
sx,
attributes,
keepOpenOnClick,
@@ -164,6 +165,10 @@ export const Notification: React.FC<NotificationProps> = ({
return (
<Snackbar
open={open}
+ autoHideDuration={autoHideDuration}
+ onClose={(_, reason) => {
+ if (reason === "timeout") onClose();
+ }}
anchorOrigin={{
horizontal: horizontal ?? "right",
vertical: vertical ?? "bottom",