diff --git a/components/notification-badge.tsx b/components/notification-badge.tsx index 4a62fed6..5dd95401 100644 --- a/components/notification-badge.tsx +++ b/components/notification-badge.tsx @@ -1,8 +1,17 @@ -import React, { memo } from 'react'; +import React, { memo, useState } from 'react'; import Link from 'next/link'; -import { Bell } from 'lucide-react'; +import { Bell, Check, ExternalLink } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { useNotifications } from '@/hooks/use-notifications'; +import { Button } from '@/components/ui/button'; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, + DropdownMenuSeparator, +} from '@/components/ui/dropdown-menu'; +import { formatDistanceToNow } from 'date-fns'; interface NotificationBadgeProps { className?: string; @@ -10,29 +19,115 @@ interface NotificationBadgeProps { // Use React.memo to prevent unnecessary re-renders export const NotificationBadge = memo(function NotificationBadge({ className }: NotificationBadgeProps) { - const { notificationCount } = useNotifications(); + const { notifications, notificationCount, markAsRead, markAllAsRead } = useNotifications(); const hasUnread = notificationCount.unread > 0; + const [isOpen, setIsOpen] = useState(false); console.log('[NOTIFICATION_BADGE] Current notification count:', notificationCount); + const handleMarkAsRead = async (notificationId: string) => { + await markAsRead(notificationId); + }; + + const handleMarkAllAsRead = async () => { + await markAllAsRead(); + setIsOpen(false); + }; + + // Take the latest 5 notifications for the dropdown + const recentNotifications = notifications.slice(0, 5); + return (
No notifications
+
+ {notification.title}
+ {!notification.isRead && (
+
+ {formatDistanceToNow(new Date(notification.timestamp), { addSuffix: true })} +
+{notification.message}
+