feat: implement tenant OAuth flow and guest achievements
This commit is contained in:
@@ -8,6 +8,9 @@ export function usePollGalleryDelta(slug: string) {
|
||||
const [newCount, setNewCount] = useState(0);
|
||||
const latestAt = useRef<string | null>(null);
|
||||
const timer = useRef<number | null>(null);
|
||||
const [visible, setVisible] = useState(
|
||||
typeof document !== 'undefined' ? document.visibilityState === 'visible' : true
|
||||
);
|
||||
|
||||
async function fetchDelta() {
|
||||
try {
|
||||
@@ -75,16 +78,25 @@ export function usePollGalleryDelta(slug: string) {
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const onVis = () => setVisible(document.visibilityState === 'visible');
|
||||
document.addEventListener('visibilitychange', onVis);
|
||||
return () => document.removeEventListener('visibilitychange', onVis);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
latestAt.current = null;
|
||||
setPhotos([]);
|
||||
fetchDelta();
|
||||
timer.current = window.setInterval(fetchDelta, 30_000);
|
||||
if (timer.current) window.clearInterval(timer.current);
|
||||
// Poll less aggressively when hidden
|
||||
const interval = visible ? 30_000 : 90_000;
|
||||
timer.current = window.setInterval(fetchDelta, interval);
|
||||
return () => {
|
||||
if (timer.current) window.clearInterval(timer.current);
|
||||
};
|
||||
}, [slug]);
|
||||
}, [slug, visible]);
|
||||
|
||||
function acknowledgeNew() { setNewCount(0); }
|
||||
return { loading, photos, newCount, acknowledgeNew };
|
||||
|
||||
Reference in New Issue
Block a user