preserving navigation

This commit is contained in:
Davide Scaini
2026-03-30 20:27:34 +02:00
parent 0b9027b4a0
commit cb345c02a1
4 changed files with 45 additions and 0 deletions
+15
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import { onMount } from 'svelte';
import type { AthleteJson } from '../lib/types';
import { formatDate, sportIcon, sportColor } from '../lib/format';
@@ -48,6 +49,20 @@
];
let activeTab: SportTab = 'running';
let mounted = false;
$: if (mounted) {
const params = new URLSearchParams(window.location.search);
if (activeTab === 'running') params.delete('sport'); else params.set('sport', activeTab);
const qs = params.toString();
history.replaceState(null, '', qs ? `?${qs}` : window.location.pathname);
}
onMount(() => {
const sp = new URLSearchParams(window.location.search).get('sport') as SportTab | null;
if (sp && TABS.some(t => t.key === sp)) activeTab = sp;
mounted = true;
});
// Tabs that have at least one record
function hasRecords(sport: SportTab): boolean {