Skip to content

Commit

Permalink
refactor(AppNotification): add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
olafsulich committed Dec 11, 2024
1 parent dc8a82c commit 81d8b82
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/script/components/AppNotification/AppNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Toaster/> 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.
Expand All @@ -49,7 +54,7 @@ export const useAppNotification = (props?: AppNotificationOptions) => {
useEffect(() => {
setTimeout(() => {
clearRoots();
}, 1);
}, ACTION_DELAY_MS);
}, [activeWindow]);

return {
Expand All @@ -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,
Expand All @@ -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 <Toaster/> into the DOM node).
}, 1);
}, ACTION_DELAY_MS);
},
close: () => {
if (!notificationId.current) {
Expand All @@ -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]) {
Expand Down
2 changes: 0 additions & 2 deletions src/script/components/calling/CallingCell/CallingCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ export const CallingCell = ({

useEffect(() => {
amplify.subscribe(WebAppEvents.CALL.SCREEN_SHARING_ENDED, () => {
console.log('WebAppEvents.CALL.SCREEN_SHARING_ENDED');

screenSharingEndedNotification.show();
});

Expand Down

0 comments on commit 81d8b82

Please sign in to comment.