Skip to content

Commit

Permalink
🐛 Extend notification delay & fix broken delay customization
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Feb 16, 2024
1 parent 6217116 commit 54355ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 2 additions & 3 deletions client/src/app/components/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export const Notifications: React.FunctionComponent = () => {
const appContext = React.useContext(NotificationsContext);
return (
<AlertGroup isToast aria-live="polite">
{appContext.notifications.map((notification) => {
{appContext.notifications.map((notification, index) => {
return (
<Alert
title={notification.title}
variant={notification.variant}
key={notification.title}
key={`${notification.title}-${index}`}
{...(!notification.hideCloseButton && {
actionClose: (
<AlertActionCloseButton
Expand All @@ -25,7 +25,6 @@ export const Notifications: React.FunctionComponent = () => {
/>
),
})}
timeout={notification.timeout ? notification.timeout : 4000}
>
{notification.message}
</Alert>
Expand Down
18 changes: 14 additions & 4 deletions client/src/app/components/NotificationsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ interface INotificationsProvider {
}

interface INotificationsContext {
pushNotification: (notification: INotification) => void;
pushNotification: (
notification: INotification,
clearNotificationDelay?: number
) => void;
dismissNotification: (key: string) => void;
notifications: INotification[];
}
Expand All @@ -38,11 +41,18 @@ export const NotificationsProvider: React.FunctionComponent<
notification: INotification,
clearNotificationDelay?: number
) => {
setNotifications([
...notifications,
setNotifications((prevNotifications) => [
...prevNotifications,
{ ...notificationDefault, ...notification },
]);
setTimeout(() => setNotifications([]), clearNotificationDelay || 10000);

setTimeout(() => {
setNotifications((prevNotifications) => {
return prevNotifications.filter(
(notif) => notif.title !== notification.title
);
});
}, clearNotificationDelay || 8000);
};

const dismissNotification = (title: string) => {
Expand Down

0 comments on commit 54355ae

Please sign in to comment.