From cb345c02a1f26c2a25983bfc3bd6d51ed878dd98 Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Mon, 30 Mar 2026 20:27:34 +0200 Subject: [PATCH] preserving navigation --- site/src/components/ActivityFeed.svelte | 10 ++++++++++ site/src/components/AthleteView.svelte | 10 ++++++++++ site/src/components/RecordsView.svelte | 15 +++++++++++++++ site/src/components/StatsView.svelte | 10 ++++++++++ 4 files changed, 45 insertions(+) diff --git a/site/src/components/ActivityFeed.svelte b/site/src/components/ActivityFeed.svelte index 48cd65a..7390af8 100644 --- a/site/src/components/ActivityFeed.svelte +++ b/site/src/components/ActivityFeed.svelte @@ -34,6 +34,7 @@ let shown = PAGE_SIZE; let loading = true; let error = ''; + let mounted = false; $: filtered = sport === 'all' ? all : all.filter(a => a.sport === sport); $: visible = filtered.slice(0, shown); @@ -41,7 +42,16 @@ $: if (sport) shown = PAGE_SIZE; // reset pagination on filter change + $: if (mounted) { + const params = new URLSearchParams(window.location.search); + if (sport === 'all') params.delete('sport'); else params.set('sport', sport); + 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'; + mounted = true; try { const res = await fetch(`${import.meta.env.BASE_URL}data/index.json`); if (!res.ok) throw new Error(`HTTP ${res.status}`); diff --git a/site/src/components/AthleteView.svelte b/site/src/components/AthleteView.svelte index c20e642..822e984 100644 --- a/site/src/components/AthleteView.svelte +++ b/site/src/components/AthleteView.svelte @@ -13,10 +13,20 @@ type Tab = 'power' | 'records' | 'profile'; let activeTab: Tab = 'power'; + let mounted = false; const editUrl = import.meta.env.PUBLIC_EDIT_URL ?? ''; + $: if (mounted) { + const params = new URLSearchParams(window.location.search); + if (activeTab === 'power') params.delete('tab'); else params.set('tab', activeTab); + const qs = params.toString(); + history.replaceState(null, '', qs ? `?${qs}` : window.location.pathname); + } + onMount(async () => { + activeTab = (new URLSearchParams(window.location.search).get('tab') as Tab) ?? 'power'; + mounted = true; try { const [athleteRes, indexRes] = await Promise.all([ fetch(`${import.meta.env.BASE_URL}data/athlete.json`), diff --git a/site/src/components/RecordsView.svelte b/site/src/components/RecordsView.svelte index 7f2cf91..0ee7b5d 100644 --- a/site/src/components/RecordsView.svelte +++ b/site/src/components/RecordsView.svelte @@ -1,4 +1,5 @@