const { socket: novuSocket } = useSocket();
const { notifications, refetch, markAsSeen } = useNotifications();
const handleNewNotification = async () => {
await refetch();
console.log(notifications)
notifications.forEach((n) => {
showNotification({
id: n._id,
title: 'New Notification',
message: `${n.content}`,
autoClose: false,
onClose: ({ id }) => {
markAsSeen(id);
}
})
})
}
useEffect(() => {
if (novuSocket) {
novuSocket.on('unseen_count_changed', async (data) => {
console.log(data);
handleNewNotification();
});
}
return () => {
if (novuSocket) {
novuSocket.off('unseen_count_changed');
}
}
}, [novuSocket])
const { socket: novuSocket } = useSocket();
const { notifications, refetch, markAsSeen } = useNotifications();
const handleNewNotification = async () => {
await refetch();
console.log(notifications)
notifications.forEach((n) => {
showNotification({
id: n._id,
title: 'New Notification',
message: `${n.content}`,
autoClose: false,
onClose: ({ id }) => {
markAsSeen(id);
}
})
})
}
useEffect(() => {
if (novuSocket) {
novuSocket.on('unseen_count_changed', async (data) => {
console.log(data);
handleNewNotification();
});
}
return () => {
if (novuSocket) {
novuSocket.off('unseen_count_changed');
}
}
}, [novuSocket])