Skip to content
Open
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: 5 additions & 0 deletions frontend/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,11 @@ section { position: relative; padding: 120px 40px; }
font-weight: 600;
font-size: 13px;
}
.notif-panel-actions {
display: flex;
align-items: center;
gap: 10px;
}
.notif-mark-all {
background: transparent;
border: none;
Expand Down
42 changes: 33 additions & 9 deletions frontend/components/NotificationsBell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
fetchNotifications,
fetchUnreadCount,
markAllRead,
clearNotifications,
markNotificationRead,
type Notification,
} from "@/lib/notifications";
Expand Down Expand Up @@ -115,6 +116,18 @@ export function NotificationsBell({ userId }: { userId: string }) {
await markAllRead(supabase, userId);
}

async function onClearAll() {
const confirmed = window.confirm(
"Clear all notifications? This cannot be undone.",
);
if (!confirmed) return;

setItems([]);
setUnread(0);
const supabase = createClient();
await clearNotifications(supabase, userId);
}

const hasItems = items.length > 0;
const badge = unread > 99 ? "99+" : unread > 0 ? String(unread) : null;

Expand Down Expand Up @@ -146,15 +159,26 @@ export function NotificationsBell({ userId }: { userId: string }) {
<div className="notif-panel" role="menu">
<div className="notif-panel-head">
<span className="notif-panel-title">Notifications</span>
{unread > 0 && (
<button
type="button"
className="notif-mark-all"
onClick={onMarkAll}
>
Mark all read
</button>
)}
<span className="notif-panel-actions">
{unread > 0 && (
<button
type="button"
className="notif-mark-all"
onClick={onMarkAll}
>
Mark all read
</button>
)}
{hasItems && (
<button
type="button"
className="notif-mark-all"
onClick={onClearAll}
>
Clear all
</button>
)}
</span>
</div>

{loading && <div className="notif-state">Loading…</div>}
Expand Down
12 changes: 12 additions & 0 deletions frontend/lib/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ export async function markAllRead(
if (error) console.warn("[markAllRead]", error);
}

/** Delete all notifications for the current user. */
export async function clearNotifications(
supabase: DBClient,
userId: string,
): Promise<void> {
const { error } = await supabase
.from("notifications" as never)
.delete()
.eq("user_id", userId);
if (error) console.warn("[clearNotifications]", error);
}

/* ---------------------------------------------------------------- */
/* Writers — call from the action that produced the event. */
/* ---------------------------------------------------------------- */
Expand Down