~bigbes/lethe

ref: 3ae44b2876001b8a2b0e4d8abfd7a35d4a8fa977 lethe/web/src/features/stats/useStats.ts -rw-r--r-- 628 bytes
3ae44b28 — Eugene Blikh tooling: adopt go tool directives; rename air→dev; bundle fmt drift a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { useQuery } from '@tanstack/react-query'
import type { UseQueryResult } from '@tanstack/react-query'
import { apiFetch } from '../../api/client'
import { adaptStats } from '../../api/adapters'
import type { Stats, StatsDTO } from '../../api/adapters'

export function useStats(range: '7d' | '30d' | '90d' | 'all'): UseQueryResult<Stats> {
  return useQuery({
    queryKey: ['stats', range],
    queryFn: async () => {
      const params = new URLSearchParams()
      params.set('range', range)
      const data = await apiFetch<StatsDTO>(`/api/v1/stats?${params.toString()}`)
      return adaptStats(data)
    },
  })
}