mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-11 13:56:16 +00:00
feat: enhance notifications functionality with sync and visibility change handling
This commit is contained in:
@@ -130,6 +130,32 @@ export default function Notifications() {
|
|||||||
return () => unsubscribe();
|
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 mergedNotifications = useMemo<MergedNotification[]>(() => {
|
||||||
const sortByDate = (a: MergedNotification, b: MergedNotification) =>
|
const sortByDate = (a: MergedNotification, b: MergedNotification) =>
|
||||||
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
|
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
|
||||||
|
|||||||
@@ -116,5 +116,6 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
text-align: left;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user