feat(roadtrip): share trip preferences and improve service stops

This commit is contained in:
Maurice
2026-09-12 00:24:45 +02:00
parent dd6ad31ab9
commit b773faff70
72 changed files with 1136 additions and 375 deletions
+5 -1
View File
@@ -13,7 +13,7 @@ import { getOfflinePrefs } from './offlinePrefs'
import { randomId } from '../utils/randomId'
import type { QueuedMutation } from '../db/offlineDb'
import type { Table } from 'dexie'
import { assignmentSchema } from '@trek/shared'
import { roadtripPreferencesResponseSchema, assignmentSchema } from '@trek/shared'
import { cacheAssignment } from '../db/cacheAssignment'
// Map Dexie table names used in `resource` field → actual Dexie tables.
@@ -195,6 +195,10 @@ export const mutationQueue = {
headers,
})
if (mutation.resource === 'roadtripPreferences') {
const saved = roadtripPreferencesResponseSchema.parse(response.data)
await offlineDb.roadtripPreferences.put(saved)
}
// Apply canonical server response to Dexie
if (mutation.resource === 'assignments') {
await cacheAssignment(assignmentSchema.parse(response.data.assignment))
@@ -357,3 +357,5 @@ describe('tripSyncManager.syncAll — background tile pass', () => {
expect(prefetchMock).not.toHaveBeenCalled()
})
})
vi.mock('../repo/roadtripPreferencesRepo', () => ({ roadtripPreferencesRepo: { read: vi.fn(async () => ({})) } }))
+4
View File
@@ -1,3 +1,4 @@
import { roadtripPreferencesRepo } from '../repo/roadtripPreferencesRepo'
/**
* Trip sync manager — seeds Dexie with trip data for offline use.
*
@@ -114,6 +115,9 @@ function isVideo(file: TripFile): boolean {
async function syncTrip(tripId: number): Promise<void> {
const bundle = await tripsApi.bundle(tripId) as TripBundle
await roadtripPreferencesRepo.read(tripId).catch((error: unknown) => {
if ((error as { response?: { status?: number } }).response?.status !== 404) throw error
})
await upsertTrip(bundle.trip)
await upsertDays(bundle.days)
await upsertPlaces(bundle.places)