prevent double broadcast notification
This commit is contained in:
@@ -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();
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user