2026-03-24 18:10:32 +01:00
|
|
|
import { useGlobalFilters } from '@cameleer/design-system';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the given interval when auto-refresh is enabled, or `false` when paused.
|
|
|
|
|
* Use as `refetchInterval` in React Query hooks.
|
|
|
|
|
*/
|
|
|
|
|
export function useRefreshInterval(intervalMs: number): number | false {
|
|
|
|
|
const { autoRefresh } = useGlobalFilters();
|
|
|
|
|
return autoRefresh ? intervalMs : false;
|
|
|
|
|
}
|
2026-03-25 10:01:14 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns `enabled` and `refetchInterval` tied to the LIVE/PAUSED toggle.
|
|
|
|
|
* - LIVE: enabled=true, refetchInterval=intervalMs (fetch + poll)
|
|
|
|
|
* - PAUSED: enabled=false, refetchInterval=false (no fetch at all)
|
|
|
|
|
*/
|
|
|
|
|
export function useLiveQuery(intervalMs: number) {
|
|
|
|
|
const { autoRefresh } = useGlobalFilters();
|
|
|
|
|
return {
|
|
|
|
|
enabled: autoRefresh,
|
|
|
|
|
refetchInterval: autoRefresh ? intervalMs : false as number | false,
|
|
|
|
|
};
|
|
|
|
|
}
|