feat(default): add real rankings data

This commit is contained in:
CaIon
2026-05-06 18:20:02 +08:00
parent 0f9f094a48
commit f8cf9c57c4
41 changed files with 1498 additions and 1912 deletions
+9 -13
View File
@@ -1,15 +1,11 @@
import { useMemo } from 'react'
import { buildRankingsSnapshot } from '../lib/mock-rankings'
import type { RankingPeriod, RankingsSnapshot } from '../types'
import { useQuery } from '@tanstack/react-query'
import { getRankings } from '../api'
import type { RankingPeriod } from '../types'
/**
* Memoised rankings snapshot for a period.
*
* Currently this synchronously builds deterministic mock data. When the
* backend ships real analytics endpoints, swap the body to a
* `useQuery`-based fetch — the consuming components don't care which side
* produced the data as long as it conforms to {@link RankingsSnapshot}.
*/
export function useRankings(period: RankingPeriod): RankingsSnapshot {
return useMemo(() => buildRankingsSnapshot(period), [period])
export function useRankings(period: RankingPeriod) {
return useQuery({
queryKey: ['rankings', period],
queryFn: () => getRankings(period),
staleTime: 5 * 60 * 1000,
})
}