Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Extend notification delay & fix broken delay customization #1690

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading