~bigbes/lethe

ref: 26d77892c6cfd3215a6d55bdb6315ec2d2b2fb00 lethe/web/src/features/stats/useStats.ts -rw-r--r-- 628 bytes
26d77892 — Eugene Blikh web: align tool-call hide selector 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)
    },
  })
}