Files
TREK/client/src/utils/needsConnection.ts
T
Maurice bdd8c08dd4 fix(planner): places put on a day, day names, day notes and trip details changed offline wait in the queue and sync once the connection is back
The day plan wrote straight to the API, so offline a place dropped on a day
snapped back with "Error assigning place", a renamed day or a new day note
failed, and a moved stop, a leg's travel mode or who joins a visit were lost.
Visits (put on a day, taken off, reordered, moved, travellers, leg mode), the
day's name, notes text and travel mode, and the day notes (add, edit, delete,
move) now go through assignmentRepo, dayRepo and dayNoteRepo and the mutation
queue: the cached day changes at once, a visit or note made offline gets a
temporary id that the edits after it wait for, and an online write held behind
an older queued one joins the queue, since none of these carry a version
token. A new order of a day that names a visit made offline is sent with its
real id, or without it when its create failed. Desktop, the phone timeline and
note sheet all write through the store, so both are covered.

The replay reads each answer for what it names: the day answer keeps the
cached notes and visits, the participants answer lands on its visit, and a
visit the server refuses with 409 (a Tour already on that day) fails instead
of waiting as a conflict no retry can solve.

The trip's name, description, reminder and the archive flag wait in the queue
too, from the planner, the phone and the dashboard. What only the server can
do says so instead of failing: new dates, a day count, a currency or a cover,
a new trip, a copy or a delete, members, guests, share and invite links, and
a new order of the days, which moves the dates of the bookings.

Refs #2601
2026-10-12 20:17:57 +02:00

24 lines
1.0 KiB
TypeScript

import { isEffectivelyOffline } from '../sync/networkMode';
/**
* For a write the offline queue cannot hold: data that is not kept on the
* device (Collab, packing bags, road trip stops) or a change only the server
* can make (an upload, an import, a member looked up). Offline it says so in
* the user's language and answers true, so the caller stops before the request
* fails with a bare network error.
*/
export function refusedOffline(toast: { error: (message: string) => unknown }, t: (key: string) => string): boolean {
if (!isEffectivelyOffline()) return false;
toast.error(t('common.needsConnection'));
return true;
}
/**
* The message for a write that failed: offline the hint that it needs a
* connection, otherwise the caller's own. For the writes whose failure handling
* (a modal that stays open, a list read again) should run as before.
*/
export function offlineOr(t: (key: string) => string, message: string): string {
return isEffectivelyOffline() ? t('common.needsConnection') : message;
}