feat: offline read fallback + online status indicator

All GET calls in client.ts now fall back to Dexie when a network error
(TypeError) is caught, so pages render from cached data when the server
is unreachable:

- entries.list()       → db.entries filtered by day_key range
- days.list()          → db.closed_days filtered by day_key range
- weeks.list()         → db.closed_weeks filtered by week_key range
- weeks.balance()      → computed locally from closed_weeks + balance_adjustments
- balance.list()       → db.balance_adjustments ordered by effective_at DESC
- settings.current()   → db.settings_history, latest row with effective_from <= today
- settings.history()   → db.settings_history ordered by effective_from DESC

Day/week close and reopen remain online-only (they require server-side
computation).

Add isOnline store (navigator.onLine + window online/offline events) and
an amber 'Offline — showing cached data' banner in +layout.svelte shown
whenever the store is false.
This commit is contained in:
2026-05-01 09:47:14 +02:00
parent 31535e944d
commit 725df56cc8
3 changed files with 104 additions and 10 deletions
+14
View File
@@ -4,6 +4,7 @@
import { onMount, onDestroy } from 'svelte';
import { goto } from '$app/navigation';
import { startSync, stopSync } from '$lib/stores/sync';
import { isOnline } from '$lib/stores/online';
import { todayKey, currentWeekKey } from '$lib/utils';
let { children } = $props();
@@ -39,6 +40,10 @@
<a href="/settings" class:active={page.url.pathname === '/settings'}>Settings</a>
</nav>
{#if !$isOnline}
<div class="offline-banner" role="status">Offline — showing cached data</div>
{/if}
<main>
{@render children()}
</main>
@@ -83,6 +88,15 @@
background: #0f3460;
color: #e9ecef;
}
.offline-banner {
background: #856404;
color: #fff3cd;
text-align: center;
padding: 0.35rem 1rem;
font-size: 0.8rem;
font-weight: 500;
letter-spacing: 0.02em;
}
main {
max-width: 800px;
margin: 0 auto;