diff --git a/site/src/components/StatsView.svelte b/site/src/components/StatsView.svelte index f004707..50a34bf 100644 --- a/site/src/components/StatsView.svelte +++ b/site/src/components/StatsView.svelte @@ -3,21 +3,30 @@ import type { ActivitySummary, BASIndex, Sport } from '../lib/types'; import { formatDistance, formatDuration, sportIcon, sportColor, sportLabel } from '../lib/format'; + const PAGE_YEARS = 4; + let all: ActivitySummary[] = []; let sport: Sport | 'all' = 'all'; + let page = 0; let loading = true; let theme = 'dark'; let mounted = false; + $: totalPages = Math.ceil(allYears.length / PAGE_YEARS); + $: years = allYears.slice(page * PAGE_YEARS, (page + 1) * PAGE_YEARS); + $: if (mounted) { const params = new URLSearchParams(window.location.search); if (sport === 'all') params.delete('sport'); else params.set('sport', sport); + if (page === 0) params.delete('page'); else params.set('page', String(page)); const qs = params.toString(); history.replaceState(null, '', qs ? `?${qs}` : window.location.pathname); } onMount(async () => { - sport = (new URLSearchParams(window.location.search).get('sport') as Sport | 'all') ?? 'all'; + const params = new URLSearchParams(window.location.search); + sport = (params.get('sport') as Sport | 'all') ?? 'all'; + page = parseInt(params.get('page') ?? '0', 10) || 0; mounted = true; const res = await fetch(`${import.meta.env.BASE_URL}data/index.json`); const index: BASIndex = await res.json(); @@ -209,8 +218,6 @@ : ([] as Sport[]); // ── Calendar helpers ────────────────────────────────────────────────────── - const now = new Date(); - const years = [now.getFullYear(), now.getFullYear()-1, now.getFullYear()-2, now.getFullYear()-3]; function localISO(d: Date): string { return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; @@ -277,9 +284,26 @@
{:else} + +{#if totalPages > 1} +{year}