prevent double broadcast notification

This commit is contained in:
2026-03-19 17:12:38 +01:00
parent 72d2cfae27
commit 4d4df673d0
+7 -13
View File
@@ -25,30 +25,25 @@ function Header() {
const notificationRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!user) return;
updateEvent();
let echoInstance: ReturnType<typeof initEcho> | null = null;
let channelsToLeave: string[] = [];
async function initializeHeader() {
try {
const echo = initEcho();
echoInstance = echo;
adminNotificationsListener(echo, user, setNotifications, setunreadNotification, updatePendingMembers);
userNotificationsListener(echo, user, setNotifications, setunreadNotification);
const notifData = await getUserNotifications();
const data: Notification[] = notifData || [];
setNotifications(data);
const hasUnread = data.some(n => n.pivot && n.pivot.unread === 1);
setunreadNotification(hasUnread);
const echo = initEcho();
echoInstance = echo;
const activeChannels: (string | null)[] = [
adminNotificationsListener(echo, user, setNotifications, setunreadNotification, updatePendingMembers),
userNotificationsListener(echo, user, setNotifications, setunreadNotification),
];
channelsToLeave = activeChannels.filter((name): name is string => name !== null);
} catch (err) {
console.error("Erreur initialisation Header:", err);
}
@@ -65,13 +60,12 @@ function Header() {
setnotificationMenu(false);
}
};
document.addEventListener("mousedown", handleClickOutside);
return () => {
document.removeEventListener("mousedown", handleClickOutside);
if (echoInstance) {
channelsToLeave.forEach(chan => echoInstance!.leave(chan));
echoInstance.disconnect();
}
};
}, []);