feat(tours): show a city walk's progress on the phone's day row, and check its stops off offline (CW-03)

The day row on the phone now shows how many stops of a city walk were
visited on that day, "2 of 5 visited", like the desktop row does. Both rows
read it from one place, and a tap on the phone names it in full without
opening the row.

A walk's stops can be checked off, skipped and taken back without a
connection. The mark shows at once, waits in the offline queue and goes out
when the connection is back, in the order the marks were made and behind any
older mark of the same day that still waits. The day plan, the walk's detail
and a reload read the visits kept on this device with the waiting marks on
top, so a mark made offline stays on screen until the server has it. A mark
the server answers with "not found", because the stop, the day or the walk
was removed meanwhile, counts as done and holds back no later mark of that
day. Any other refusal, the Tours addon turned off among them, keeps the mark
as a failed change to try again from the offline settings. The visits are
read again when the connection comes and goes, and once more after the
waiting marks went out, so a mark the server dropped or refused leaves the
day plan. A trip's visits that answer after another trip was opened no longer
show there.

The offline sync keeps each trip's walk visits and reads the stops of a walk
this device has never opened, so it can be checked off offline too. A walk
whose stops this device could not read lists no stand-in stops and no count,
and says to open it again while online. A walk put on a day while offline
says its stops can be checked off once it has synced, instead of offering
buttons that cannot work yet. A mark that fails says to open the walk again
and try once more, in every language.

Marks carry no version, so the last one to reach the server wins, as with
the other changes sent after being offline. The offline guide says so.
This commit is contained in:
Maurice
2026-10-20 02:14:12 +00:00
parent c836ee3988
commit 0b92dcc86b
56 changed files with 1884 additions and 122 deletions
+36
View File
@@ -0,0 +1,36 @@
import type { TourVisit } from '@trek/shared';
import { offlineDb, type CachedTourStationVisit } from './offlineDb';
function rowOf(tripId: number, visit: TourVisit): CachedTourStationVisit {
return { assignment_id: visit.assignment_id, station_key: visit.station_key, status: visit.status, trip_id: tripId };
}
/**
* CW-03: a trip's walk visits as the server listed them. The rows it no longer
* lists go, so a stop taken back on another device does not come back offline.
*/
export async function replaceTripVisits(tripId: number, visits: readonly TourVisit[]): Promise<void> {
await offlineDb.transaction('rw', offlineDb.tourStationVisits, async () => {
await offlineDb.tourStationVisits.where('trip_id').equals(tripId).delete();
await offlineDb.tourStationVisits.bulkPut(visits.map((visit) => rowOf(tripId, visit)));
});
}
/** One day's visits of a walk as the server answered a mark of it; the other days stay as they are. */
export async function replaceAssignmentVisits(
tripId: number,
assignmentId: number,
visits: readonly TourVisit[]
): Promise<void> {
const own = visits.filter((visit) => visit.assignment_id === assignmentId);
await offlineDb.transaction('rw', offlineDb.tourStationVisits, async () => {
await offlineDb.tourStationVisits.where('assignment_id').equals(assignmentId).delete();
await offlineDb.tourStationVisits.bulkPut(own.map((visit) => rowOf(tripId, visit)));
});
}
/** The trip's walk visits as last cached, without the trip they were filed under. */
export async function cachedTripVisits(tripId: number): Promise<TourVisit[]> {
const rows = await offlineDb.tourStationVisits.where('trip_id').equals(tripId).toArray();
return rows.map((row) => ({ assignment_id: row.assignment_id, station_key: row.station_key, status: row.status }));
}
+19 -1
View File
@@ -1,4 +1,4 @@
import type { Ferrata, RoadtripPreferences, TourListItem, TourObstacleCheck, TourProvenance, TourWaypoint } from '@trek/shared';
import type { Ferrata, RoadtripPreferences, TourListItem, TourObstacleCheck, TourProvenance, TourVisit, TourWaypoint } from '@trek/shared';
import Dexie, { type Table } from 'dexie';
import type { Trip, Day, Place, PackingItem, TodoItem, BudgetItem, Reservation, TripFile, Accommodation, TripMember, Tag, Category } from '../types';
@@ -46,6 +46,16 @@ interface CachedFerrataTile {
ferratas: Ferrata[];
}
/**
* CW-03: a station of a city walk visited or skipped on one of its days, as the
* server last said, with the trip it belongs to so it drops with the trip. A
* mark made offline is not written here: it waits in the queue, and every read
* lays it over these rows (see repo/tourVisitRepo).
*/
export interface CachedTourStationVisit extends TourVisit {
trip_id: number;
}
// ── Queue + sync types ────────────────────────────────────────────────────────
// 'conflict' is terminal-until-resolved: the server rejected the replay because
@@ -253,6 +263,7 @@ export class TrekOfflineDb extends Dexie {
tours!: Table<CachedTour, number>;
budgetSettlements!: Table<CachedBudgetSettlement, number>;
ferrataTiles!: Table<CachedFerrataTile, [number, string]>;
tourStationVisits!: Table<CachedTourStationVisit, [number, string]>;
constructor(name: string = ANON_DB_NAME) {
super(name);
@@ -331,6 +342,11 @@ export class TrekOfflineDb extends Dexie {
// v11: the via ferrata layer's loaded tiles, per trip, so the lines draw at
// once and offline; `tripId` so they drop with the trip.
this.version(11).stores({ ferrataTiles: '[tripId+tile], tripId, fetchedAt' });
// v12: the visits of the city walks, one row per station and day, so a
// walk's stops read as checked off offline; `trip_id` so they drop with the
// trip, `assignment_id` so one day's visits are replaced at once.
this.version(12).stores({ tourStationVisits: '[assignment_id+station_key], trip_id, assignment_id' });
}
}
@@ -620,6 +636,7 @@ export async function clearTripData(tripId: number): Promise<void> {
offlineDb.tours,
offlineDb.budgetSettlements,
offlineDb.ferrataTiles,
offlineDb.tourStationVisits,
],
async () => {
await offlineDb.roadtripPreferences.delete(tripId);
@@ -633,6 +650,7 @@ export async function clearTripData(tripId: number): Promise<void> {
await offlineDb.tripFiles.where('trip_id').equals(tripId).delete();
await offlineDb.accommodations.where('trip_id').equals(tripId).delete();
await offlineDb.tours.where('trip_id').equals(tripId).delete();
await offlineDb.tourStationVisits.where('trip_id').equals(tripId).delete();
await offlineDb.tripMembers.where('tripId').equals(tripId).delete();
await offlineDb.syncMeta.where('tripId').equals(tripId).delete();
await offlineDb.blobCache.where('tripId').equals(tripId).delete();