mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 15:40:06 +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:
@@ -98,4 +98,28 @@ export const assignmentRepo = {
|
||||
mutationQueue.sendSoon()
|
||||
return updated
|
||||
},
|
||||
/**
|
||||
* The note a visit carries on its day (#2163). Saved through here rather than straight
|
||||
* to the API so the cached day holds the new note too: the tab never sees its own
|
||||
* `assignment:updated` echo, and a trip reopened offline reads its days from the cache.
|
||||
* A write of the same visit still waiting in the queue keeps this one behind it.
|
||||
*/
|
||||
async setNotes(tripId: number | string, assignment: Assignment, notes: string | null): Promise<Assignment> {
|
||||
if (!(await mutationQueue.mustQueue('assignments', assignment.id))) {
|
||||
const saved = assignmentSchema.parse((await assignmentsApi.updateNotes(tripId, assignment.id, { notes })).assignment)
|
||||
await cacheAssignment(saved)
|
||||
return saved
|
||||
}
|
||||
const updated = { ...assignment, notes }
|
||||
await offlineDb.transaction('rw', offlineDb.days, offlineDb.mutationQueue, async () => {
|
||||
await mutationQueue.enqueue({
|
||||
id: generateUUID(), tripId: Number(tripId), method: 'PUT',
|
||||
url: `/trips/${tripId}/assignments/${assignment.id}/notes`,
|
||||
body: { notes }, resource: 'assignments', entityId: assignment.id,
|
||||
})
|
||||
await cacheAssignment(updated)
|
||||
})
|
||||
mutationQueue.sendSoon()
|
||||
return updated
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user