This commit is contained in:
2026-05-28 12:34:01 -04:00
parent d239de257d
commit 49310e6d59
9 changed files with 240 additions and 164 deletions
+20 -2
View File
@@ -1,6 +1,6 @@
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { useEffect } from 'react'
import { getStats } from '../lib/api'
import { getScanStatus, getStats } from '../lib/api'
export function useStats() {
const queryClient = useQueryClient()
@@ -20,5 +20,23 @@ export function useStats() {
return () => es.close()
}, [queryClient])
return useQuery({ queryKey: ['stats'], queryFn: getStats, refetchInterval: 30_000 })
const scanStatusQuery = useQuery({
queryKey: ['scanStatus'],
queryFn: getScanStatus,
refetchInterval: (query) => (query.state.data?.scanning ? 1000 : 5000),
})
const isScanning = scanStatusQuery.data?.scanning ?? true
const statsQuery = useQuery({
queryKey: ['stats'],
queryFn: getStats,
enabled: !isScanning,
refetchInterval: isScanning ? false : 30_000,
})
return {
...statsQuery,
isScanning,
}
}
+1
View File
@@ -13,6 +13,7 @@ export async function apiFetch(path, options = {}) {
}
export const getStats = () => apiFetch('/stats')
export const getScanStatus = () => apiFetch('/scan-status')
export const getTests = (params = {}) => {
const qs = new URLSearchParams(
Object.entries(params).filter(([, v]) => v !== '' && v !== undefined && v !== null)