preserving navigation
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
let shown = PAGE_SIZE;
|
let shown = PAGE_SIZE;
|
||||||
let loading = true;
|
let loading = true;
|
||||||
let error = '';
|
let error = '';
|
||||||
|
let mounted = false;
|
||||||
|
|
||||||
$: filtered = sport === 'all' ? all : all.filter(a => a.sport === sport);
|
$: filtered = sport === 'all' ? all : all.filter(a => a.sport === sport);
|
||||||
$: visible = filtered.slice(0, shown);
|
$: visible = filtered.slice(0, shown);
|
||||||
@@ -41,7 +42,16 @@
|
|||||||
|
|
||||||
$: if (sport) shown = PAGE_SIZE; // reset pagination on filter change
|
$: 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 () => {
|
onMount(async () => {
|
||||||
|
sport = (new URLSearchParams(window.location.search).get('sport') as Sport | 'all') ?? 'all';
|
||||||
|
mounted = true;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${import.meta.env.BASE_URL}data/index.json`);
|
const res = await fetch(`${import.meta.env.BASE_URL}data/index.json`);
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||||
|
|||||||
@@ -13,10 +13,20 @@
|
|||||||
|
|
||||||
type Tab = 'power' | 'records' | 'profile';
|
type Tab = 'power' | 'records' | 'profile';
|
||||||
let activeTab: Tab = 'power';
|
let activeTab: Tab = 'power';
|
||||||
|
let mounted = false;
|
||||||
|
|
||||||
const editUrl = import.meta.env.PUBLIC_EDIT_URL ?? '';
|
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 () => {
|
onMount(async () => {
|
||||||
|
activeTab = (new URLSearchParams(window.location.search).get('tab') as Tab) ?? 'power';
|
||||||
|
mounted = true;
|
||||||
try {
|
try {
|
||||||
const [athleteRes, indexRes] = await Promise.all([
|
const [athleteRes, indexRes] = await Promise.all([
|
||||||
fetch(`${import.meta.env.BASE_URL}data/athlete.json`),
|
fetch(`${import.meta.env.BASE_URL}data/athlete.json`),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { onMount } from 'svelte';
|
||||||
import type { AthleteJson } from '../lib/types';
|
import type { AthleteJson } from '../lib/types';
|
||||||
import { formatDate, sportIcon, sportColor } from '../lib/format';
|
import { formatDate, sportIcon, sportColor } from '../lib/format';
|
||||||
|
|
||||||
@@ -48,6 +49,20 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
let activeTab: SportTab = 'running';
|
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
|
// Tabs that have at least one record
|
||||||
function hasRecords(sport: SportTab): boolean {
|
function hasRecords(sport: SportTab): boolean {
|
||||||
|
|||||||
@@ -7,8 +7,18 @@
|
|||||||
let sport: Sport | 'all' = 'all';
|
let sport: Sport | 'all' = 'all';
|
||||||
let loading = true;
|
let loading = true;
|
||||||
let theme = 'dark';
|
let theme = 'dark';
|
||||||
|
let mounted = false;
|
||||||
|
|
||||||
|
$: 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 () => {
|
onMount(async () => {
|
||||||
|
sport = (new URLSearchParams(window.location.search).get('sport') as Sport | 'all') ?? 'all';
|
||||||
|
mounted = true;
|
||||||
const res = await fetch(`${import.meta.env.BASE_URL}data/index.json`);
|
const res = await fetch(`${import.meta.env.BASE_URL}data/index.json`);
|
||||||
const index: BASIndex = await res.json();
|
const index: BASIndex = await res.json();
|
||||||
all = index.activities.filter(a => a.privacy !== 'private' && a.distance_m);
|
all = index.activities.filter(a => a.privacy !== 'private' && a.distance_m);
|
||||||
|
|||||||
Reference in New Issue
Block a user