feat: add caching for backend objects

This commit is contained in:
2026-04-21 19:38:57 -04:00
parent 5b4955f07e
commit 7f1e82acc2
14 changed files with 637 additions and 62 deletions

View File

@@ -55,6 +55,27 @@ You work with Patrick, a Solutions Architect, on the OYS Borrow a Boat app (oysq
- Ionicons only (`ionicons/icons`) — no PrimeIcons
- Always import individual icon names from `ionicons/icons` (tree-shakeable)
### Offline Cache
- **Rule**: Every table/view read from Supabase must be written to `useAppCache` on success and read from it when offline.
- **Composables**: `useAppCache` (localStorage, 24h TTL), `useOfflineStatus` (reactive `isOnline`)
- **Pattern** for any data fetch:
```typescript
const cache = useAppCache()
const { isOnline } = useOfflineStatus()
if (!isOnline.value) {
const cached = cache.peek<T>('my-key')
if (cached) data.value = cached
return
}
const { data: fresh } = await supabase.from('my_table').select('*')
data.value = fresh ?? []
if (fresh) cache.set('my-key', fresh)
```
- **Schedule data** is keyed by ISO week Monday: `cache.weekKey(utcIso)` → use keys `intervals:{monday}` and `slots:{monday}`.
- **Realtime**: `app/app.vue` subscribes to `reservations`, `intervals`, and `boats` changes and patches the cache in real time. When adding a new table subscription, add it to the `app-cache-sync` channel in `app.vue`.
- **Cross-page navigation state** (not persistence): use `useBookingDraft` as a pattern — module-level `ref` set by the source page, consumed (`take()`) by the destination page. Do not use query params for structured objects.
## Rules
1. Do not mix unrelated project contexts in one session.