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
|
|
|
|
|
|
|
|
/**
|
2026-04-03 22:05:29 +02:00
|
|
|
* Returns `enabled` and `refetchInterval` tied to the AUTO/MANUAL toggle.
|
|
|
|
|
* - AUTO: enabled=true, refetchInterval=intervalMs (fetch + poll)
|
|
|
|
|
* - MANUAL: enabled=true, refetchInterval=false (fetch once, no polling)
|
2026-03-25 10:01:14 +01:00
|
|
|
*/
|
|
|
|
|
export function useLiveQuery(intervalMs: number) {
|
|
|
|
|
const { autoRefresh } = useGlobalFilters();
|
|
|
|
|
return {
|
2026-04-03 11:25:04 +02:00
|
|
|
enabled: true,
|
2026-03-25 10:01:14 +01:00
|
|
|
refetchInterval: autoRefresh ? intervalMs : false as number | false,
|
|
|
|
|
};
|
|
|
|
|
}
|