feat: enhance notifications functionality with sync and visibility change handling

This commit is contained in:
Moyasee
2025-12-27 04:15:15 +02:00
parent a01e1b1709
commit 96b12cb27e
2 changed files with 27 additions and 0 deletions

View File

@@ -130,6 +130,32 @@ export default function Notifications() {
return () => unsubscribe();
}, []);
useEffect(() => {
const unsubscribe = window.electron.onSyncNotificationCount(() => {
if (userDetails) {
fetchApiNotifications(0, false);
}
fetchLocalNotifications();
});
return () => unsubscribe();
}, [userDetails, fetchApiNotifications, fetchLocalNotifications]);
useEffect(() => {
const handleVisibilityChange = () => {
if (!document.hidden && userDetails) {
fetchApiNotifications(0, false);
fetchLocalNotifications();
}
};
document.addEventListener("visibilitychange", handleVisibilityChange);
return () => {
document.removeEventListener("visibilitychange", handleVisibilityChange);
};
}, [userDetails, fetchApiNotifications, fetchLocalNotifications]);
const mergedNotifications = useMemo<MergedNotification[]>(() => {
const sortByDate = (a: MergedNotification, b: MergedNotification) =>
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();

View File

@@ -116,5 +116,6 @@
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-align: left;
}
}