~bigbes/lethe

ref: 2d9d2b8ec08ee09cc64c5d925ab85716b1d7d1fb lethe/web/src/features/stats/useStats.ts -rw-r--r-- 628 bytes
2d9d2b8e — Eugene Blikh search: add /api/v1/search API and opencode collector parser 24 days 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)
    },
  })
}