Just sub it once

This commit is contained in:
Lim Chee Aun 2024-04-10 17:31:26 +08:00
parent c9124bf150
commit 8b5fee3dfd

View file

@ -247,7 +247,6 @@ function Notifications({ columnMode }) {
const lastHiddenTime = useRef(); const lastHiddenTime = useRef();
usePageVisibility((visible) => { usePageVisibility((visible) => {
let unsub;
if (visible) { if (visible) {
const timeDiff = Date.now() - lastHiddenTime.current; const timeDiff = Date.now() - lastHiddenTime.current;
if (!lastHiddenTime.current || timeDiff > 1000 * 3) { if (!lastHiddenTime.current || timeDiff > 1000 * 3) {
@ -258,20 +257,16 @@ function Notifications({ columnMode }) {
} else { } else {
lastHiddenTime.current = Date.now(); lastHiddenTime.current = Date.now();
} }
unsub = subscribeKey(states, 'notificationsShowNew', (v) => {
if (uiState === 'loading') {
return;
}
if (v) {
loadUpdates();
} }
});
useEffect(() => {
let unsub = subscribeKey(states, 'notificationsShowNew', (v) => {
if (uiState === 'loading') return;
if (v) loadUpdates();
setShowNew(v); setShowNew(v);
}); });
} return () => unsub?.();
return () => { }, []);
unsub?.();
};
});
const todayDate = new Date(); const todayDate = new Date();
const yesterdayDate = new Date(todayDate - 24 * 60 * 60 * 1000); const yesterdayDate = new Date(todayDate - 24 * 60 * 60 * 1000);