The week view no longer loads its data on demand and patches it after each mutation. Entries, closed days, the closed week and the settings are derived from the synced collections, so the view follows local changes and sync results. Closing and reopening a week report errors from the server in place.
44 lines
1.4 KiB
Svelte
44 lines
1.4 KiB
Svelte
<script lang="ts">
|
|
import { page } from '$app/stores';
|
|
import { goto } from '$app/navigation';
|
|
import { todayKey } from '$lib/app.svelte';
|
|
import { currentWeekKey, defaultDayForWeek } from '$lib/utils';
|
|
import WeekView from '$lib/components/WeekView.svelte';
|
|
|
|
let weekKey = $derived(
|
|
$page.url.searchParams.get('week') ?? currentWeekKey()
|
|
);
|
|
let selectedDay = $derived(
|
|
$page.url.searchParams.get('day') ?? defaultDayForWeek(weekKey, todayKey())
|
|
);
|
|
|
|
// Canonicalize bare /week (no params) via replaceState so bookmarks work.
|
|
$effect(() => {
|
|
const url = $page.url;
|
|
if (!url.searchParams.has('week') || !url.searchParams.has('day')) {
|
|
const wk = url.searchParams.get('week') ?? currentWeekKey();
|
|
const dk = url.searchParams.get('day') ?? defaultDayForWeek(wk, todayKey());
|
|
const next = new URL(url);
|
|
next.searchParams.set('week', wk);
|
|
next.searchParams.set('day', dk);
|
|
goto(next.toString(), { replaceState: true, noScroll: true, keepFocus: true });
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<WeekView
|
|
{weekKey}
|
|
{selectedDay}
|
|
onweekchange={(wk, dk) => {
|
|
const next = new URL($page.url);
|
|
next.searchParams.set('week', wk);
|
|
next.searchParams.set('day', dk);
|
|
goto(next.toString(), { noScroll: true, keepFocus: true });
|
|
}}
|
|
ondaychange={(dk) => {
|
|
const next = new URL($page.url);
|
|
next.searchParams.set('day', dk);
|
|
goto(next.toString(), { replaceState: true, noScroll: true, keepFocus: true });
|
|
}}
|
|
/>
|