From 62bf03d07a5073385c8c436062569ac05af2e0b7 Mon Sep 17 00:00:00 2001 From: Mathis HERRIOT <197931332+0x485254@users.noreply.github.com> Date: Thu, 29 Jan 2026 16:56:19 +0100 Subject: [PATCH] feat: implement `NotificationHandler` component for real-time notifications - Added `NotificationHandler` component for managing real-time notifications using sockets. - Display notifications for comments, replies, likes, and messages with interactive toasts. - Integrated click handling for navigation to relevant pages based on notification type. --- .../src/components/notification-handler.tsx | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 frontend/src/components/notification-handler.tsx diff --git a/frontend/src/components/notification-handler.tsx b/frontend/src/components/notification-handler.tsx new file mode 100644 index 0000000..a6440f2 --- /dev/null +++ b/frontend/src/components/notification-handler.tsx @@ -0,0 +1,116 @@ +"use client"; + +import { Bell, Heart, MessageCircle, Reply } from "lucide-react"; +import { useRouter } from "next/navigation"; +import * as React from "react"; +import { toast } from "sonner"; +import { useSocket } from "@/providers/socket-provider"; + +interface NotificationData { + type: "comment" | "reply" | "like_comment" | "message"; + userId: string; + username: string; + contentId?: string; + commentId?: string; + text: string; +} + +export function NotificationHandler() { + const { socket } = useSocket(); + const router = useRouter(); + + React.useEffect(() => { + if (!socket) return; + + const handleNotification = (data: NotificationData) => { + // Ne pas afficher de toast si on est déjà sur la page des messages pour un nouveau message + if (data.type === "message" && window.location.pathname === "/messages") { + return; + } + + toast.custom( + (t) => ( +
@{data.username}
+{data.text}
+