♻️ Read the week view reactively from SignalDB
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.
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { currentWeekKey, todayKey } from '$lib/utils';
|
||||
import { todayKey } from '$lib/app.svelte';
|
||||
import { currentWeekKey } from '$lib/utils';
|
||||
import WeekView from '$lib/components/WeekView.svelte';
|
||||
|
||||
const weekKey = currentWeekKey();
|
||||
let selectedDay = $state(todayKey());
|
||||
let pickedDay = $state<string | null>(null);
|
||||
let selectedDay = $derived(pickedDay ?? todayKey());
|
||||
</script>
|
||||
|
||||
<WeekView
|
||||
{weekKey}
|
||||
{selectedDay}
|
||||
onweekchange={(wk, dk) => goto(`/week?week=${wk}&day=${dk}`)}
|
||||
ondaychange={(dk) => { selectedDay = dk; }}
|
||||
ondaychange={(dk) => { pickedDay = dk; }}
|
||||
/>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<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';
|
||||
|
||||
@@ -8,7 +9,7 @@
|
||||
$page.url.searchParams.get('week') ?? currentWeekKey()
|
||||
);
|
||||
let selectedDay = $derived(
|
||||
$page.url.searchParams.get('day') ?? defaultDayForWeek(weekKey)
|
||||
$page.url.searchParams.get('day') ?? defaultDayForWeek(weekKey, todayKey())
|
||||
);
|
||||
|
||||
// Canonicalize bare /week (no params) via replaceState so bookmarks work.
|
||||
@@ -16,7 +17,7 @@
|
||||
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);
|
||||
const dk = url.searchParams.get('day') ?? defaultDayForWeek(wk, todayKey());
|
||||
const next = new URL(url);
|
||||
next.searchParams.set('week', wk);
|
||||
next.searchParams.set('day', dk);
|
||||
|
||||
Reference in New Issue
Block a user