preserving navigation
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user