llm-router / apps /web /src /hooks /useSlipQueueCounts.ts
ClaraSu's picture
Upload folder using huggingface_hub
747e1c6 verified
Raw History Blame Contribute Delete
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 }
}