mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
fix(client): make the new rollbacks roll back only what they wrote
The rollbacks this branch added were snapshot-shaped: capture the whole collection before the write, restore it on any failure. That is wrong in two ways at once. It undoes work the server already accepted when a later step is the one that fails, and it throws away whatever a collaborator's socket event applied while the requests were in flight. The day-plan reorder is the clearest case: five awaits, and a failing day-note write reverted transport positions the server had already stored. It now records only the fields it is about to overwrite, per booking, and drops each one as its request lands - so a note failure reaches the catch with nothing to undo, and a booking that arrived mid-write survives. The notification toggle had the same shape underneath: the rollback was made surgical but the request still shipped the whole matrix built from the pre-toggle render, so two overlapping toggles overwrote each other anyway. It sends the one cell that changed. The test pinned the disagreement as correct; it asserts the payload now. Photo reorder awaits allSettled rather than all, so the UI is not snapped back while the remaining writes are still landing - a partial run really does leave the server holding part of the new order, and only a total refusal justifies restoring the old one. Both the desktop editor and the mobile sheet, which was still swallowing every rejection. Also: the geolocation start guard is a run generation now, because a start issued after a stop re-sets a plain flag while the first run is still parked in the iOS permission prompt; a category rename reports once for the batch and rethrows, so the settings dialog stops closing as if it had worked; and a 404'd import job stops telling the user their file was invalid when it had simply expired. The clipboard fallback for plain-HTTP installs was pasted into three files by this branch. It is one helper now, and the two copy buttons in the members modal that still called navigator.clipboard unguarded use it too. Same for the fourth local-date helper written next to the three that already import the existing one.
This commit is contained in:
@@ -102,11 +102,16 @@ export function useGeolocation(): UseGeolocationReturn {
|
||||
const watchIdRef = useRef<number | null>(null)
|
||||
// True between the start of startWatch and the watchPosition call it awaits.
|
||||
const startingRef = useRef(false)
|
||||
// Bumped by every start and by every stop, so a run parked on the iOS prompt can
|
||||
// tell it has been superseded — clearing startingRef alone can't, a start that came
|
||||
// after the stop has set it again by then.
|
||||
const startRunRef = useRef(0)
|
||||
const orientationHandlerRef = useRef<((e: DeviceOrientationEvent) => void) | null>(null)
|
||||
const headingRef = useRef<number | null>(null)
|
||||
|
||||
const stopWatch = useCallback(() => {
|
||||
startingRef.current = false
|
||||
startRunRef.current++
|
||||
if (watchIdRef.current !== null) {
|
||||
try { navigator.geolocation.clearWatch(watchIdRef.current) } catch { /* noop */ }
|
||||
watchIdRef.current = null
|
||||
@@ -129,6 +134,7 @@ export function useGeolocation(): UseGeolocationReturn {
|
||||
// with nobody left holding its id.
|
||||
if (startingRef.current || watchIdRef.current !== null) return true
|
||||
startingRef.current = true
|
||||
const run = ++startRunRef.current
|
||||
setError(null)
|
||||
|
||||
// iOS: ask for orientation permission up front; on Android and desktop
|
||||
@@ -142,6 +148,9 @@ export function useGeolocation(): UseGeolocationReturn {
|
||||
}
|
||||
} catch { /* older webkit throws — ignore and proceed */ }
|
||||
}
|
||||
// Stopped (or restarted) while the prompt was open: subscribing now would leave a
|
||||
// watch running that nobody holds the id of any more.
|
||||
if (startRunRef.current !== run) return false
|
||||
|
||||
// Device orientation → compass heading. `alpha` is rotation around the
|
||||
// Z-axis (0 = facing magnetic north on most devices). The webkit-only
|
||||
|
||||
Reference in New Issue
Block a user