- Phase 3: new migration 20260824000000_redesign.sql (contacts/events/registrations/sponsors, slot types, session speakers + feedback/material), seed rewrite - Phase 4: APPE Admin rebrand + Contacts/Registrations/Sponsors/Schedule/Activity/Events views - Phase 5: Convivo App (24h login, 5s polling, QR type badge, red dot, speaker material) - Phase 6: APPE favicon + PWA icons for both apps - Docs: schema/rpcs/rls/seed/screens/api-client/admin-app/architecture/next-steps/README/roadmap updated Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
32 lines
932 B
TypeScript
32 lines
932 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
|
|
/**
|
|
* Runs `fn` every `ms` milliseconds, but ONLY while the tab is visible
|
|
* (document.visibilityState === 'visible'). Also re-runs immediately when the
|
|
* tab becomes visible again. No background polling.
|
|
*/
|
|
export function usePolling(fn: () => void, ms: number, enabled = true): void {
|
|
const saved = useRef(fn);
|
|
saved.current = fn;
|
|
|
|
useEffect(() => {
|
|
if (!enabled) return;
|
|
let timer: number | undefined;
|
|
|
|
const tick = () => {
|
|
if (document.visibilityState === 'visible') saved.current();
|
|
};
|
|
|
|
timer = window.setInterval(tick, ms);
|
|
const onVis = () => {
|
|
if (document.visibilityState === 'visible') tick();
|
|
};
|
|
document.addEventListener('visibilitychange', onVis);
|
|
|
|
return () => {
|
|
if (timer !== undefined) window.clearInterval(timer);
|
|
document.removeEventListener('visibilitychange', onVis);
|
|
};
|
|
}, [ms, enabled]);
|
|
}
|