Spaces:
Runtime error
Runtime error
Download apps/web/src/hooks/useSlipQueueCounts.ts from ClaraSu/llm-router: direct link, hf CLI and curl.
- Browser
- Download file 886 Bytes
-
https://huggingface.co/spaces/ClaraSu/llm-router/resolve/main/apps/web/src/hooks/useSlipQueueCounts.ts
- Command line
-
hf download hf://spaces/ClaraSu/llm-router/apps/web/src/hooks/useSlipQueueCounts.ts
-
curl -L -o useSlipQueueCounts.ts https://huggingface.co/spaces/ClaraSu/llm-router/resolve/main/apps/web/src/hooks/useSlipQueueCounts.ts
886 Bytes
| import { useState, useEffect, useCallback } from 'react' | |
| import { getSlipQueueCounts } from '@/api/slip-queue' | |
| import type { SlipStatus } from '@/api/slip-queue' | |
| // Polled independently of whichever tab is open — the badge numbers should | |
| // stay live even while looking at a different tab's page. | |
| const POLL_INTERVAL_MS = 5000 | |
| export function useSlipQueueCounts() { | |
| const [counts, setCounts] = useState<Record<SlipStatus, number> | null>(null) | |
| const refresh = useCallback(async () => { | |
| try { | |
| const data = await getSlipQueueCounts() | |
| setCounts(data) | |
| } catch { | |
| // Best-effort — badges just keep their last known values on failure. | |
| } | |
| }, []) | |
| useEffect(() => { | |
| void refresh() | |
| const interval = setInterval(() => { void refresh() }, POLL_INTERVAL_MS) | |
| return () => clearInterval(interval) | |
| }, [refresh]) | |
| return { counts, refresh } | |
| } | |