π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[web] Restart timeout for replacement notifications
AswinAsoke6a4599a3544
diff --git a/web/apps/share/src/components/file-share/CollectionShareView.tsx b/web/apps/share/src/components/file-share/CollectionShareView.tsxindex 4631cce70e..e8fd0054b1 100644--- a/web/apps/share/src/components/file-share/CollectionShareView.tsx+++ b/web/apps/share/src/components/file-share/CollectionShareView.tsx@@ -85,13 +85,12 @@ export const CollectionShareView: React.FC = () => {error,collectionInfo,selectedItem,- notificationAttributes,+ notificationProps,handleItemClick,handleCloseItem,handleDownload,handleSubmitPassword,handleCopyContent,- setNotificationAttributes,} = useCollectionShare();const passwordTitle = translatedOrFallback("password", "Password");const passwordDescription = translatedOrFallback(@@ -393,11 +392,7 @@ export const CollectionShareView: React.FC = () => {</Box>)}- <Notification- open={!!notificationAttributes}- onClose={() => setNotificationAttributes(undefined)}- attributes={notificationAttributes}- />+ <Notification {...notificationProps} /></PublicShareScaffold>);};diff --git a/web/apps/share/src/components/file-share/FileShareView.tsx b/web/apps/share/src/components/file-share/FileShareView.tsxindex bce4f78b05..8a4ed02570 100644--- a/web/apps/share/src/components/file-share/FileShareView.tsx+++ b/web/apps/share/src/components/file-share/FileShareView.tsx@@ -13,10 +13,9 @@ export const FileShareView: React.FC = () => {downloading,error,fileInfo,- notificationAttributes,+ notificationProps,handleDownload,handleCopyContent,- setNotificationAttributes,} = useFileShare();const iconInfo = fileInfo? getLockerFileIcon(fileInfo.fileName, {@@ -285,11 +284,7 @@ export const FileShareView: React.FC = () => {)}</Box>- <Notification- open={!!notificationAttributes}- onClose={() => setNotificationAttributes(undefined)}- attributes={notificationAttributes}- />+ <Notification {...notificationProps} /></Box></Box></>diff --git a/web/apps/share/src/hooks/use-collection-share.ts b/web/apps/share/src/hooks/use-collection-share.tsindex 8ff9130e8a..8ca3ebf01c 100644--- a/web/apps/share/src/hooks/use-collection-share.ts+++ b/web/apps/share/src/hooks/use-collection-share.ts@@ -1,5 +1,5 @@-import type { NotificationAttributes } from "ente-base/components/Notification";import type { SingleInputFormProps } from "ente-base/components/SingleInputForm";+import { useNotification } from "ente-base/components/utils/hooks-app";import {HTTPError,isHTTP401Error,@@ -37,15 +37,12 @@ interface UseCollectionShareResult {error: string | null;collectionInfo: PublicCollectionShareInfo | null;selectedItem: SharedCollectionItemInfo | null;- notificationAttributes: NotificationAttributes | undefined;+ notificationProps: ReturnType<typeof useNotification>["notificationProps"];handleItemClick: (item: SharedCollectionItemInfo) => void;handleCloseItem: () => void;handleDownload: () => Promise<void>;handleSubmitPassword: SingleInputFormProps["onSubmit"];handleCopyContent: (content: string) => Promise<void>;- setNotificationAttributes: (- attributes: NotificationAttributes | undefined,- ) => void;}interface CollectionShareLoadError {@@ -205,8 +202,7 @@ export const useCollectionShare = (): UseCollectionShareResult => {const [collectionKey, setCollectionKey] = useState<string | null>(null);const [passwordProtectedPublicURL, setPasswordProtectedPublicURL] =useState<PublicURL | null>(null);- const [notificationAttributes, setNotificationAttributes] =- useState<NotificationAttributes>();+ const { showNotification, notificationProps } = useNotification();const requiresPassword = !!passwordProtectedPublicURL && !accessTokenJWT;const clearLoadedState = useCallback(() => {setCollectionInfo(null);@@ -499,7 +495,7 @@ export const useCollectionShare = (): UseCollectionShareResult => {await loadCollection({ accessToken, collectionKey });return;}- setNotificationAttributes({+ showNotification({color: "critical",title:err instanceof Error@@ -531,10 +527,7 @@ export const useCollectionShare = (): UseCollectionShareResult => {try {await navigator.clipboard.writeText(content);} catch {- setNotificationAttributes({- color: "critical",- title: "Failed to copy",- });+ showNotification({ color: "critical", title: "Failed to copy" });}};@@ -577,12 +570,11 @@ export const useCollectionShare = (): UseCollectionShareResult => {error,collectionInfo,selectedItem,- notificationAttributes,+ notificationProps,handleItemClick,handleCloseItem,handleDownload,handleSubmitPassword,handleCopyContent,- setNotificationAttributes,};};diff --git a/web/apps/share/src/hooks/use-file-share.ts b/web/apps/share/src/hooks/use-file-share.tsindex c8d25d4878..5fbb75b3a9 100644--- a/web/apps/share/src/hooks/use-file-share.ts+++ b/web/apps/share/src/hooks/use-file-share.ts@@ -1,4 +1,4 @@-import type { NotificationAttributes } from "ente-base/components/Notification";+import { useNotification } from "ente-base/components/utils/hooks-app";import { apiOrigin } from "ente-base/origins";import { useRouter } from "next/router";import { useEffect, useState } from "react";@@ -44,12 +44,9 @@ interface UseFileShareResult {error: string | null;fileInfo: DecryptedFileInfo | null;accessToken: string | null;- notificationAttributes: NotificationAttributes | undefined;+ notificationProps: ReturnType<typeof useNotification>["notificationProps"];handleDownload: () => Promise<void>;handleCopyContent: (content: string) => Promise<void>;- setNotificationAttributes: (- attributes: NotificationAttributes | undefined,- ) => void;}export const useFileShare = (): UseFileShareResult => {@@ -59,8 +56,7 @@ export const useFileShare = (): UseFileShareResult => {const [error, setError] = useState<string | null>(null);const [fileInfo, setFileInfo] = useState<DecryptedFileInfo | null>(null);const [accessToken, setAccessToken] = useState<string | null>(null);- const [notificationAttributes, setNotificationAttributes] =- useState<NotificationAttributes>();+ const { showNotification, notificationProps } = useNotification();useEffect(() => {const loadFileInfo = async () => {@@ -157,10 +153,7 @@ export const useFileShare = (): UseFileShareResult => {try {await navigator.clipboard.writeText(content);} catch {- setNotificationAttributes({- color: "critical",- title: "Failed to copy",- });+ showNotification({ color: "critical", title: "Failed to copy" });}};@@ -170,9 +163,8 @@ export const useFileShare = (): UseFileShareResult => {error,fileInfo,accessToken,- notificationAttributes,+ notificationProps,handleDownload,handleCopyContent,- setNotificationAttributes,};};diff --git a/web/packages/base/components/Notification.tsx b/web/packages/base/components/Notification.tsxindex f3b6823236..106aa55141 100644--- a/web/packages/base/components/Notification.tsx+++ b/web/packages/base/components/Notification.tsx@@ -36,6 +36,8 @@ export interface NotificationAttributes {type NotificationProps = ModalVisibilityProps & {attributes: NotificationAttributes | undefined;+ /** A new event restarts the timeout, even when its message is unchanged. */+ notificationID?: number;keepOpenOnClick?: boolean;horizontal?: "left" | "right";autoHideDuration?: number | null;@@ -59,6 +61,7 @@ const actionButtonSx = {export const Notification: React.FC<NotificationProps> = ({open,+ notificationID,onClose,horizontal = "right",autoHideDuration,@@ -162,6 +165,7 @@ export const Notification: React.FC<NotificationProps> = ({return (<Snackbar+ key={notificationID}open={open}autoHideDuration={resolvedAutoHideDuration}onClose={(_, reason) => {diff --git a/web/packages/base/components/utils/hooks-app.ts b/web/packages/base/components/utils/hooks-app.tsindex 40228f90f3..b40eede40f 100644--- a/web/packages/base/components/utils/hooks-app.ts+++ b/web/packages/base/components/utils/hooks-app.ts@@ -62,9 +62,11 @@ export const useNotification = () => {>(undefined);const [open, setOpen] = useState(false);+ const [notificationID, setNotificationID] = useState(0);const showNotification = useCallback((attributes: NotificationAttributes) => {+ setNotificationID((id) => id + 1);setAttributes(attributes);setOpen(true);},@@ -75,6 +77,11 @@ export const useNotification = () => {return {showNotification,- notificationProps: { open, onClose: handleClose, attributes },+ notificationProps: {+ notificationID,+ open,+ onClose: handleClose,+ attributes,+ },};};