From 81d8b824474b127f4d9ed667e41f21cdc3e4817c Mon Sep 17 00:00:00 2001 From: Olaf Sulich Date: Wed, 11 Dec 2024 13:26:12 +0100 Subject: [PATCH] refactor(AppNotification): add comments --- .../AppNotification/AppNotification.tsx | 18 ++++++++++-------- .../calling/CallingCell/CallingCell.tsx | 2 -- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/script/components/AppNotification/AppNotification.tsx b/src/script/components/AppNotification/AppNotification.tsx index 420aac12bf7..53f7b09fa06 100644 --- a/src/script/components/AppNotification/AppNotification.tsx +++ b/src/script/components/AppNotification/AppNotification.tsx @@ -32,9 +32,14 @@ interface AppNotificationOptions { autoClose?: boolean; } -const DEFAULT_NOTIFICATION_TIMEOUT = 3000; +const NOTIFICATION_TIMEOUT_MS = 3000; const APP_NOTIFICATION_SELECTOR = '#app-notification'; +// Small delay to ensure rendering is complete. +// In some cases (switching between windows) the notification is not displayed without this delay. +// It's caused by the rendering behavior of the toast library (injecting the into the DOM node). +const ACTION_DELAY_MS = 1; + // Stores React roots for different windows (activeWindow). // Each window (identified by its 'name' property or 'default' if not available) gets its own root. // This prevents multiple calls to createRoot() for the same container, ensuring a single root per window. @@ -49,7 +54,7 @@ export const useAppNotification = (props?: AppNotificationOptions) => { useEffect(() => { setTimeout(() => { clearRoots(); - }, 1); + }, ACTION_DELAY_MS); }, [activeWindow]); return { @@ -67,7 +72,7 @@ export const useAppNotification = (props?: AppNotificationOptions) => { /> ), { - duration: props?.autoClose === false ? Infinity : DEFAULT_NOTIFICATION_TIMEOUT, + duration: props?.autoClose === false ? Infinity : NOTIFICATION_TIMEOUT_MS, position: 'top-center', unstyled: true, dismissible: false, @@ -77,10 +82,7 @@ export const useAppNotification = (props?: AppNotificationOptions) => { }, ); notificationId.current = id; - // Small delay to ensure rendering is complete. - // In some cases (switching between windows) the notification is not displayed without this delay. - // It's caused by the rendering behavior of the toast library (injecting the into the DOM node). - }, 1); + }, ACTION_DELAY_MS); }, close: () => { if (!notificationId.current) { @@ -92,7 +94,7 @@ export const useAppNotification = (props?: AppNotificationOptions) => { }; }; -const injectToaster = (activeWindow: Window) => { +export const injectToaster = (activeWindow: Window) => { const windowKey = activeWindow.name || 'default'; if (roots[windowKey]) { diff --git a/src/script/components/calling/CallingCell/CallingCell.tsx b/src/script/components/calling/CallingCell/CallingCell.tsx index 0782374c794..166ae27e8de 100644 --- a/src/script/components/calling/CallingCell/CallingCell.tsx +++ b/src/script/components/calling/CallingCell/CallingCell.tsx @@ -169,8 +169,6 @@ export const CallingCell = ({ useEffect(() => { amplify.subscribe(WebAppEvents.CALL.SCREEN_SHARING_ENDED, () => { - console.log('WebAppEvents.CALL.SCREEN_SHARING_ENDED'); - screenSharingEndedNotification.show(); });