mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
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:
@@ -1,4 +1,5 @@
|
||||
import { roadtripPreferencesRepo } from '../repo/roadtripPreferencesRepo'
|
||||
import { tourRepo } from '../repo/tourRepo'
|
||||
/**
|
||||
* Trip sync manager — seeds Dexie with trip data for offline use.
|
||||
*
|
||||
@@ -12,6 +13,8 @@ import { roadtripPreferencesRepo } from '../repo/roadtripPreferencesRepo'
|
||||
* - WS reconnect (phase 7)
|
||||
*/
|
||||
import { tripsApi, tagsApi, categoriesApi, toursApi } from '../api/client'
|
||||
import { tourVisitsApi } from '../api/tourVisits'
|
||||
import { replaceTripVisits } from '../db/cacheTourVisits'
|
||||
import {
|
||||
offlineDb,
|
||||
upsertTrip,
|
||||
@@ -153,13 +156,30 @@ async function syncTrip(tripId: number): Promise<void> {
|
||||
// sync of many trips does not spend a refused request on each.
|
||||
if (useAddonStore.getState().isEnabled('tours')) {
|
||||
try {
|
||||
await replaceTripTours(tripId, (await toursApi.list(tripId)).tours)
|
||||
await cacheTripTours(tripId)
|
||||
} catch (err) {
|
||||
console.warn(`[sync] tours for trip ${tripId} not cached:`, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A trip's tours and, for its city walks, the stops checked off on their days
|
||||
* (CW-03), so a walk still shows how far it got offline. A walk whose stops
|
||||
* this device never read, one planned on another device, has them read here
|
||||
* too, each walk on its own: one that cannot be read leaves the others alone,
|
||||
* and offline its card then lists no stops to check off.
|
||||
*/
|
||||
async function cacheTripTours(tripId: number): Promise<void> {
|
||||
const { tours } = await toursApi.list(tripId)
|
||||
await replaceTripTours(tripId, tours)
|
||||
const walks = tours.filter(tour => tour.tour_type === 'walk')
|
||||
await replaceTripVisits(tripId, walks.length > 0 ? (await tourVisitsApi.list(tripId)).visits : [])
|
||||
const cached = await offlineDb.tours.bulkGet(walks.map(walk => walk.place_id))
|
||||
const unread = walks.filter((_walk, index) => !cached[index]?.waypoints?.length)
|
||||
await Promise.allSettled(unread.map(walk => tourRepo.detail(tripId, walk.place_id)))
|
||||
}
|
||||
|
||||
/** Cache non-photo file blobs for a trip. Fire-and-forget safe. */
|
||||
async function cacheFilesForTrip(tripId: number, files: TripFile[]): Promise<void> {
|
||||
const nonPhotos = files.filter(f => f.url && !isPhoto(f) && !isVideo(f))
|
||||
|
||||
Reference in New Issue
Block a user