- Today nav link targets /week?week=<currentWeek>&day=<todayKey> - Today tab active: route=/week AND ?day===todayKey() (not just pathname) - Week tab active: route=/week AND today tab not active - Root / redirect updated from /today to /week?week=…&day=… - /today route hard-deleted (src/routes/today/ removed) - +layout.svelte imports todayKey/currentWeekKey for link generation
92 lines
1.9 KiB
Svelte
92 lines
1.9 KiB
Svelte
<script lang="ts">
|
|
import { page } from '$app/state';
|
|
import { hasToken } from '$lib/api/client';
|
|
import { onMount, onDestroy } from 'svelte';
|
|
import { goto } from '$app/navigation';
|
|
import { startSync, stopSync } from '$lib/stores/sync';
|
|
import { todayKey, currentWeekKey } from '$lib/utils';
|
|
|
|
let { children } = $props();
|
|
|
|
onMount(() => {
|
|
if (!hasToken() && page.url.pathname !== '/settings') {
|
|
goto('/settings');
|
|
}
|
|
startSync();
|
|
});
|
|
|
|
onDestroy(stopSync);
|
|
|
|
function todayHref(): string {
|
|
return `/week?week=${currentWeekKey()}&day=${todayKey()}`;
|
|
}
|
|
|
|
// "Today" tab is active when on /week with ?day === todayKey().
|
|
const todayActive = $derived(
|
|
page.url.pathname === '/week' &&
|
|
page.url.searchParams.get('day') === todayKey()
|
|
);
|
|
|
|
const weekActive = $derived(
|
|
page.url.pathname === '/week' && !todayActive
|
|
);
|
|
</script>
|
|
|
|
<nav>
|
|
<a href={todayHref()} class:active={todayActive}>Today</a>
|
|
<a href="/week" class:active={weekActive}>Week</a>
|
|
<a href="/history" class:active={page.url.pathname === '/history'}>History</a>
|
|
<a href="/settings" class:active={page.url.pathname === '/settings'}>Settings</a>
|
|
</nav>
|
|
|
|
<main>
|
|
{@render children()}
|
|
</main>
|
|
|
|
<style>
|
|
:global(*, *::before, *::after) {
|
|
box-sizing: border-box;
|
|
}
|
|
:global(body) {
|
|
margin: 0;
|
|
font-family: system-ui, sans-serif;
|
|
background: #f8f9fa;
|
|
color: #212529;
|
|
}
|
|
:global(button) {
|
|
cursor: pointer;
|
|
}
|
|
|
|
nav {
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
padding: 0.75rem 1rem;
|
|
background: #1a1a2e;
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 10;
|
|
}
|
|
nav a {
|
|
color: #adb5bd;
|
|
text-decoration: none;
|
|
padding: 0.4rem 0.8rem;
|
|
border-radius: 6px;
|
|
font-size: 0.9rem;
|
|
font-weight: 500;
|
|
transition: background 0.15s, color 0.15s;
|
|
}
|
|
nav a:hover {
|
|
background: #16213e;
|
|
color: #e9ecef;
|
|
}
|
|
nav a.active {
|
|
background: #0f3460;
|
|
color: #e9ecef;
|
|
}
|
|
main {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 1.5rem 1rem;
|
|
}
|
|
</style>
|