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

Add clear all button in notifications #3893

Merged
merged 11 commits into from
Sep 29, 2023
19 changes: 19 additions & 0 deletions specifyweb/frontend/js_src/lib/components/Header/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ export function Notifications({
count: notifications.length,
})
: notificationsText.notificationsLoading();

function handleClearAll() {
if (notifications === undefined) return;
notifications.forEach((notification) => {
ping('/notifications/delete/', {
method: 'POST',
// eslint-disable-next-line @typescript-eslint/naming-convention
body: formData({ message_id: notification.messageId }),
errorMode: 'dismissible',
});
});
setNotifications([]);
}

return (
<>
<MenuButton
Expand Down Expand Up @@ -200,6 +214,11 @@ export function Notifications({
/>
</ErrorBoundary>
))}
{notifications.length > 0 && (
<Button.Fancy onClick={handleClearAll}>
{commonText.clearAll()}
</Button.Fancy>
)}
</Dialog>
) : isOpen ? (
<LoadingScreen />
Expand Down