mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
feat(roadtrip): share trip preferences and improve service stops
This commit is contained in:
@@ -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 () => ({})) } }))
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user