diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx index 7a33148..906c063 100644 --- a/frontend/src/components/Header.tsx +++ b/frontend/src/components/Header.tsx @@ -1,6 +1,15 @@ import React, { useState, useContext, useEffect } from "react"; import { NavLink, useLocation, useNavigate } from "react-router-dom"; -import { Bell, Menu, X, Home, BarChart, User, Info, LogOut, Check } from "lucide-react"; +import { + Bell, + Menu, + X, + Home, + BarChart, + User, + Info, + LogOut +} from "lucide-react"; import { useAtom } from "jotai"; import { userAtom } from "@/state/userAtom"; import { AuthContext } from "@/context/authContext"; @@ -21,7 +30,13 @@ import { ScrollArea } from "@/components/ui/scroll-area"; import { Button } from "@/components/ui/button"; import debateAiLogo from "@/assets/aossie.png"; import avatarImage from "@/assets/avatar2.jpg"; -import { getNotifications, markNotificationAsRead, markAllNotificationsAsRead, deleteNotification, Notification } from "@/services/notificationService"; +import { + getNotifications, + markNotificationAsRead, + markAllNotificationsAsRead, + deleteNotification, + Notification, +} from "@/services/notificationService"; function Header() { const [isDrawerOpen, setIsDrawerOpen] = useState(false); @@ -39,7 +54,7 @@ function Header() { if (user) { const data = await getNotifications(); setNotifications(data); - setUnreadCount(data.filter(n => !n.isRead).length); + setUnreadCount(data.filter((n) => !n.isRead).length); } }; @@ -53,12 +68,12 @@ function Header() { const handleNotificationClick = async (notification: Notification) => { if (!notification.isRead) { await markNotificationAsRead(notification.id); - setNotifications(prev => - prev.map(n => n.id === notification.id ? { ...n, isRead: true } : n) + setNotifications((prev) => + prev.map((n) => (n.id === notification.id ? { ...n, isRead: true } : n)) ); - setUnreadCount(prev => Math.max(0, prev - 1)); + setUnreadCount((prev) => Math.max(0, prev - 1)); } - + if (notification.link) { navigate(notification.link); setIsNotificationsOpen(false); @@ -68,17 +83,17 @@ function Header() { const handleDeleteNotification = async (e: React.MouseEvent, id: string) => { e.stopPropagation(); await deleteNotification(id); - setNotifications(prev => prev.filter(n => n.id !== id)); + setNotifications((prev) => prev.filter((n) => n.id !== id)); // Update unread count if the deleted notification was unread - const notification = notifications.find(n => n.id === id); + const notification = notifications.find((n) => n.id === id); if (notification && !notification.isRead) { - setUnreadCount(prev => Math.max(0, prev - 1)); + setUnreadCount((prev) => Math.max(0, prev - 1)); } }; const handleMarkAllRead = async () => { await markAllNotificationsAsRead(); - setNotifications(prev => prev.map(n => ({ ...n, isRead: true }))); + setNotifications((prev) => prev.map((n) => ({ ...n, isRead: true }))); setUnreadCount(0); }; @@ -121,26 +136,26 @@ function Header() { return ( <> -
+
{getBreadcrumbs()}
-
-

Notifications

+
+

Notifications

{unreadCount > 0 && ( -
{notifications.length === 0 ? ( -
+
No notifications yet
) : ( -
+
{notifications.map((notification) => ( -
handleNotificationClick(notification)} >
-
+
-

+

{notification.title}

-

+

{notification.message}

-

- {new Date(notification.createdAt).toLocaleDateString()} +

+ {new Date( + notification.createdAt + ).toLocaleDateString()}

@@ -188,47 +215,56 @@ function Header() { - + -
+
User avatar
-

{user?.displayName || "User"}

-

{user?.email || "No email"}

+

+ {user?.displayName || "User"} +

+

+ {user?.email || "No email"} +

- User ID - + User ID + {user?.id || "N/A"}
- Rating - {user?.rating ? Math.round(user.rating) : 1500} + Rating + + {user?.rating ? Math.round(user.rating) : 1500} +
-
-
+
+
- + DebateAI by