mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
b194e8317d
Add genuine offline read/write capability for trips: - Dexie IndexedDB schema (trips, places, packing, todo, budget, reservations, files, mutationQueue, syncMeta, blobCache) - Repo layer for all domains: offline reads from Dexie, writes optimistically to Dexie and enqueue mutations for later replay - Mutation queue with UUID idempotency keys (X-Idempotency-Key), FIFO flush, temp-ID reconciliation on 2xx, fail-and-continue on 4xx - Trip sync manager: caches all trips with end_date >= today or null, auto-evicts 7d after end_date, fetches bundle endpoint in one request - Map tile prefetcher: bbox from place coords, zooms 10-16, 50MB cap, warms SW cache via fetch - Sync triggers: network online → flush + syncAll; WS reconnect → flush only (rate-limiter safe); visibilitychange/30s → flush only - WS remoteEventHandler writes through to Dexie on every event - Server idempotency middleware + idempotency_keys table (migration 100, 24h TTL nightly cleanup) - GET /api/trips/:id/bundle endpoint for efficient single-request sync - OfflineBanner component: amber (offline) / blue (syncing) / hidden - OfflineTab in Settings: cached trip list, re-sync and clear actions - usePendingMutations hook for per-item pending indicators Closes #505 #541
19 lines
538 B
TypeScript
19 lines
538 B
TypeScript
import { filesApi } from '../api/client'
|
|
import { offlineDb, upsertTripFiles } from '../db/offlineDb'
|
|
import type { TripFile } from '../types'
|
|
|
|
export const fileRepo = {
|
|
async list(tripId: number | string): Promise<{ files: TripFile[] }> {
|
|
if (!navigator.onLine) {
|
|
const cached = await offlineDb.tripFiles
|
|
.where('trip_id')
|
|
.equals(Number(tripId))
|
|
.toArray()
|
|
return { files: cached }
|
|
}
|
|
const result = await filesApi.list(tripId)
|
|
upsertTripFiles(result.files)
|
|
return result
|
|
},
|
|
}
|