From 07b59b9642eefd983fd1f691fef22e7de762142b Mon Sep 17 00:00:00 2001 From: oscar24357 Date: Fri, 28 Aug 2026 15:11:09 +0100 Subject: [PATCH] feat: add dismissNotification per-item control --- components/layout/notification-bell.tsx | 29 +++++++++++++++++++------ hooks/use-notifications.ts | 10 ++++++++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/components/layout/notification-bell.tsx b/components/layout/notification-bell.tsx index c8a6426..2b54286 100644 --- a/components/layout/notification-bell.tsx +++ b/components/layout/notification-bell.tsx @@ -1,12 +1,18 @@ 'use client' import { useState, useRef, useEffect } from 'react' -import { Bell } from 'lucide-react' +import { Bell, X } from 'lucide-react' import { formatTimeAgo } from '@/lib/stream-utils' import { useWallet } from '@/hooks/use-wallet' import { useNotifications, type AppNotification } from '@/hooks/use-notifications' -function NotificationItem({ notification }: { notification: AppNotification }) { +function NotificationItem({ + notification, + onDismiss, +}: { + notification: AppNotification + onDismiss: (id: string) => void +}) { return (

{notification.title}

- {!notification.read && ( - - )} +
+ {!notification.read && ( + + )} + +

{notification.body}

{formatTimeAgo(notification.timestamp)}

@@ -28,7 +43,7 @@ function NotificationItem({ notification }: { notification: AppNotification }) { export function NotificationBell() { const { address } = useWallet() - const { notifications, unreadCount, markAllRead, clearAll } = useNotifications(address) + const { notifications, unreadCount, markAllRead, clearAll, dismissNotification } = useNotifications(address) const [open, setOpen] = useState(false) const ref = useRef(null) const triggerRef = useRef(null) @@ -105,7 +120,7 @@ export function NotificationBell() {

) : ( notifications.map((n) => ( - + )) )}
diff --git a/hooks/use-notifications.ts b/hooks/use-notifications.ts index 238dca1..bf7244a 100644 --- a/hooks/use-notifications.ts +++ b/hooks/use-notifications.ts @@ -252,6 +252,14 @@ export function useNotifications(walletAddress: string | null) { saveNotifications([]); }, []); + const dismissNotification = useCallback((id: string) => { + setNotifications((prev) => { + const updated = prev.filter((n) => n.id !== id); + saveNotifications(updated); + return updated; + }); + }, []); + useEffect(() => { const rpcUrl = config.rpcUrl; const contractId = config.streamContractId; @@ -388,5 +396,5 @@ export function useNotifications(walletAddress: string | null) { network, ]); - return { notifications, unreadCount, markAllRead, clearAll }; + return { notifications, unreadCount, markAllRead, clearAll, dismissNotification }; }