mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 18:04:18 +00:00
fix(client): cache a visit note saved from the place dialog
The place dialog stopped reloading the days after a save, so the new visit note only reached the Zustand store. Nothing wrote it to Dexie, the tab never sees its own assignment:updated echo, and the time save before it cached the server row with the old note. A trip reopened offline then showed the old note until the next full sync. The note now goes through assignmentRepo.setNotes, which caches the saved row on its day online and queues the write behind any other write of the same visit offline, like setTimes does. A new store action applies it, so the page hook no longer patches the store by hand. usePlaceEdits drops its direct API import and leaves the offline baseline.
This commit is contained in:
@@ -13,6 +13,7 @@ export interface AssignmentsSlice {
|
||||
setAssignmentEndDay: (tripId: number | string, dayId: number, assignmentId: number, endDay: boolean) => Promise<void>
|
||||
setAssignmentRouteExcluded: (tripId: number | string, dayId: number, assignmentId: number, excluded: boolean) => Promise<void>
|
||||
setAssignmentTimes: (tripId: number | string, dayId: number, assignmentId: number, times: AssignmentTimes) => Promise<void>
|
||||
setAssignmentNotes: (tripId: number | string, dayId: number, assignmentId: number, notes: string | null) => Promise<void>
|
||||
assignPlaceToDay: (tripId: number | string, dayId: number | string, placeId: number | string, position?: number | null) => Promise<Assignment | undefined>
|
||||
removeAssignment: (tripId: number | string, dayId: number | string, assignmentId: number) => Promise<void>
|
||||
clearDayAssignments: (tripId: number | string, dayId: number) => Promise<void>
|
||||
@@ -77,6 +78,25 @@ export const createAssignmentsSlice = (set: SetState, get: GetState): Assignment
|
||||
throw err
|
||||
}
|
||||
},
|
||||
setAssignmentNotes: async (tripId, dayId, assignmentId, notes) => {
|
||||
const assignment = get().assignments[String(dayId)]?.find(a => a.id === assignmentId)
|
||||
if (!assignment || assignmentId < 0) return
|
||||
// Only the note is patched: the saved row carries the place as the server has it,
|
||||
// and the visit's times may still wait in the queue ahead of this write.
|
||||
const apply = (value: string | null) => set(state => ({
|
||||
assignments: Object.fromEntries(Object.entries(state.assignments).map(([key, items]) => [
|
||||
key, items.map(a => a.id === assignmentId ? { ...a, notes: value } : a),
|
||||
])),
|
||||
}))
|
||||
apply(notes)
|
||||
try {
|
||||
const saved = await assignmentRepo.setNotes(tripId, assignment, notes)
|
||||
apply(saved.notes ?? null)
|
||||
} catch (err: unknown) {
|
||||
apply(assignment.notes ?? null)
|
||||
throw err
|
||||
}
|
||||
},
|
||||
assignPlaceToDay: async (tripId, dayId, placeId, position) => {
|
||||
const state = get()
|
||||
const place = state.places.find(p => p.id === Number.parseInt(String(placeId)))
|
||||
|
||||
Reference in New Issue
Block a user