diff --git a/backend/services/matchmaking_test.go b/backend/services/matchmaking_test.go
index 78445f74..0bc095ec 100644
--- a/backend/services/matchmaking_test.go
+++ b/backend/services/matchmaking_test.go
@@ -8,6 +8,10 @@ import (
func TestMatchmakingService(t *testing.T) {
// Get the singleton service
ms := GetMatchmakingService()
+ t.Cleanup(func() {
+ ms.RemoveFromPool("user1")
+ ms.RemoveFromPool("user2")
+ })
// Test adding users to pool (but not starting matchmaking yet)
err := ms.AddToPool("user1", "Alice", 1200)
@@ -67,6 +71,11 @@ func TestMatchmakingService(t *testing.T) {
func TestEloTolerance(t *testing.T) {
ms := GetMatchmakingService()
+ t.Cleanup(func() {
+ ms.RemoveFromPool("user1")
+ ms.RemoveFromPool("user2")
+ ms.RemoveFromPool("user3")
+ })
// Add users with different Elo ratings (but don't start matchmaking yet)
ms.AddToPool("user1", "Alice", 1200) // Range: 1000-1400
diff --git a/frontend/src/Pages/Authentication.tsx b/frontend/src/Pages/Authentication.tsx
index e0239280..757cd231 100644
--- a/frontend/src/Pages/Authentication.tsx
+++ b/frontend/src/Pages/Authentication.tsx
@@ -19,7 +19,7 @@ const LeftSection = () => (
- Arguehub
+ DebateAI
diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx
index 8ce2d81b..cfb5d167 100644
--- a/frontend/src/components/Header.tsx
+++ b/frontend/src/components/Header.tsx
@@ -35,7 +35,13 @@ import { Button } from "@/components/ui/button";
import { DebateAiLogo } from "./DebateAiLogo";
import avatarImage from "@/assets/avatar2.jpg";
import { DEFAULT_AVATAR_URL } from "@/constants/avatar";
-import { getNotifications, markNotificationAsRead, markAllNotificationsAsRead, deleteNotification, Notification } from "@/services/notificationService";
+import {
+ getNotifications,
+ markNotificationAsRead,
+ markAllNotificationsAsRead,
+ deleteNotification,
+ Notification,
+} from "@/services/notificationService";
import { ThemeToggle } from "./ThemeToggle";
import ServerBadge from "./ServerBadge";
@@ -51,10 +57,6 @@ const handleAvatarLoadError = (event: React.SyntheticEvent
) =>
image.src = avatarImage;
};
-/**
- * Header component providing breadcrumb navigation, notifications,
- * and user profile management.
- */
function Header() {
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
const location = useLocation();
@@ -65,32 +67,43 @@ function Header() {
const [unreadCount, setUnreadCount] = useState(0);
const [isNotificationsOpen, setIsNotificationsOpen] = useState(false);
+ const isSignedIn = Boolean(auth?.isAuthenticated || user);
+
const toggleDrawer = () => setIsDrawerOpen(!isDrawerOpen);
const fetchNotifications = async () => {
- if (user) {
- const data = await getNotifications();
- setNotifications(data);
- setUnreadCount(data.filter(n => !n.isRead).length);
+ if (!isSignedIn) {
+ setNotifications([]);
+ setUnreadCount(0);
+ return;
}
+
+ const data = await getNotifications();
+ setNotifications(data);
+ setUnreadCount(data.filter((n) => !n.isRead).length);
};
useEffect(() => {
+ if (!isSignedIn) {
+ setNotifications([]);
+ setUnreadCount(0);
+ return;
+ }
+
fetchNotifications();
- // Poll for notifications every minute
const interval = setInterval(fetchNotifications, 60000);
return () => clearInterval(interval);
- }, [user]);
+ }, [isSignedIn, user]);
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);
@@ -100,24 +113,19 @@ function Header() {
const handleDeleteNotification = async (e: React.MouseEvent, id: string) => {
e.stopPropagation();
await deleteNotification(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);
+ setNotifications((prev) => prev.filter((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);
};
- /**
- * Generates breadcrumb navigation based on the current URL path.
- * @returns {JSX.Element} The breadcrumb component.
- */
const getBreadcrumbs = () => {
const pathnames = location.pathname.split("/").filter((x) => x);
return (
@@ -130,10 +138,10 @@ function Header() {
{pathnames.map((value, index) => {
let to = `/${pathnames.slice(0, index + 1).join("/")}`;
- if (value === "tournament"){
+ if (value === "tournament") {
to = "/tournaments";
}
- const isLast = index === pathnames.length - 1;
+ const isLast = index === pathnames.length - 1;
return (
@@ -141,19 +149,19 @@ function Header() {
{isLast ? (
{value === "support-debateai" || value === "support-os"
- ? "Support DebateAI"
- : value === "bot-selection"
- ? "Bot Selection"
- : value.replace(/-/g, " ")}
+ ? "Support DebateAI"
+ : value === "bot-selection"
+ ? "Bot Selection"
+ : value.replace(/-/g, " ")}
) : (
{value === "support-debateai" || value === "support-os"
- ? "Support DebateAI"
- : value === "bot-selection"
- ? "Bot Selection"
- : value.replace(/-/g, " ")}
+ ? "Support DebateAI"
+ : value === "bot-selection"
+ ? "Bot Selection"
+ : value.replace(/-/g, " ")}
)}
@@ -169,141 +177,182 @@ function Header() {
return (
<>
- {getBreadcrumbs()}
+
+ {getBreadcrumbs()}
+
+
-
-
-
-
-
-
-
Notifications
- {unreadCount > 0 && (
-
+ >
+ ) : (
+ <>
+
+
+
+
- Mark all read
-
- )}
-
-
- {notifications.length === 0 ? (
-
- No notifications yet
-
- ) : (
-
- {notifications.map((notification) => (
-
handleNotificationClick(notification)}
+
+ {unreadCount > 0 && (
+
+ )}
+
+
+
+
+
Notifications
+ {unreadCount > 0 && (
+
- handleDeleteNotification(e, notification.id)}
- className="absolute top-2 right-2 p-1 text-muted-foreground hover:text-destructive opacity-100 md:opacity-0 md:group-hover:opacity-100 focus-visible:opacity-100 transition-opacity"
- title="Delete notification"
- aria-label="Delete notification"
- >
-
-
-
-
-
-
- {notification.title}
-
-
- {notification.message}
-
-
- {new Date(notification.createdAt).toLocaleDateString()}
-
+ Mark all read
+
+ )}
+
+
+ {notifications.length === 0 ? (
+
+ No notifications yet
+
+ ) : (
+
+ {notifications.map((notification) => (
+
handleNotificationClick(notification)}
+ >
+
handleDeleteNotification(e, notification.id)}
+ className="absolute top-2 right-2 p-1 text-muted-foreground hover:text-destructive opacity-100 md:opacity-0 md:group-hover:opacity-100 focus-visible:opacity-100 transition-opacity"
+ title="Delete notification"
+ aria-label="Delete notification"
+ >
+
+
+
+
+
+
+ {notification.title}
+
+
+ {notification.message}
+
+
+ {new Date(notification.createdAt).toLocaleDateString()}
+
+
+
+ ))}
+
+ )}
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+ {user?.displayName || "User"}
+
+
+ {user?.email || "No email"}
- ))}
+
+
+
+ User ID
+
+ {user?.id || "N/A"}
+
+
+
+ Rating
+
+ {user?.rating ? Math.round(user.rating) : 1500}
+
+
+
+
+
+ auth?.logout()}
+ className="w-full flex items-center gap-2 px-3 py-2 text-sm text-destructive hover:bg-destructive/10 rounded-md transition-colors"
+ >
+
+ Sign out
+
- )}
-
-
-
-
-
-
+
+
+
-
+
-
-
-
-
-

-
-
{user?.displayName || "User"}
-
{user?.email || "No email"}
-
-
-
-
- User ID
-
- {user?.id || "N/A"}
-
-
-
- Rating
- {user?.rating ? Math.round(user.rating) : 1500}
-
-
-
-
- auth?.logout()}
- className="w-full flex items-center gap-2 px-3 py-2 text-sm text-destructive hover:bg-destructive/10 rounded-md transition-colors"
- >
-
- Sign out
-
-
-
-
-
-
-
-
+ >
+ )}
@@ -318,12 +367,10 @@ function Header() {
+