feat(tours): take a tour over from another trip, the dialog (LIB-02)

The Tours tab's list of the trip's tours gains a button beside the GPX
import: take a tour over from another trip. Its dialog lists the tours of
the user's other trips, searched by name and filtered by trip and type,
each with its trip and the measures it has (time, distance, ascent; one it
lacks is left out, a paddle tour's climb too). Choosing one shows it on a
map with where it comes from, its type, distance, time, heights and number
of waypoints, and the name it gets in this trip, its own name to start
with. The note under the name says the copy is a tour of this trip of its
own, on no day yet, and that later changes stay apart.

Only the button in the foot takes it over. The new tour then comes into
the trip's lists and map and opens in the editor, unless the editor holds
unsaved work, which it never replaces. Nothing is written before the
confirm, and closing writes nothing. The library is online only: offline,
or when the list fails, the dialog says so and offers to try again; a list
cut at 100 tours says to search or filter.

A tour taken over names its source in its provenance: "Taken over from"
with the trip and the tour as they were called then.
This commit is contained in:
Maurice
2026-10-19 15:28:53 +02:00
parent f6fd2722d0
commit 692373c8b8
39 changed files with 1545 additions and 6 deletions
+48
View File
@@ -0,0 +1,48 @@
import type {
TourCreateResponse,
TourLibraryDetailResponse,
TourLibraryQuery,
TourLibraryResponse,
TourTakeOverRequest,
} from '@trek/shared';
import { tourLibraryApi } from '../api/tourLibrary';
import { cacheTourAnswer } from '../db/cacheTour';
import { isEffectivelyOffline } from '../sync/networkMode';
/** What a library call answers while there is no connection: nothing read, and the view says why. */
export class TourLibraryOfflineError extends Error {
constructor() {
super('The tour library needs a connection');
this.name = 'TourLibraryOfflineError';
}
}
function requireOnline(): void {
if (isEffectivelyOffline()) throw new TourLibraryOfflineError();
}
/**
* LIB-02, online only on purpose: the list reads across trips this device may
* never have cached and whose access the server decides at the moment it is
* asked, so an offline copy could show a tour of a trip the user has left.
* The take-over is made from the server's copy of the source, like the in-trip
* copy, and the new tour goes into this trip's cache once it exists.
*/
export const tourLibraryRepo = {
async list(query: TourLibraryQuery, signal?: AbortSignal): Promise<TourLibraryResponse> {
requireOnline();
return await tourLibraryApi.list(query, signal);
},
async detail(placeId: number, signal?: AbortSignal): Promise<TourLibraryDetailResponse> {
requireOnline();
return await tourLibraryApi.detail(placeId, signal);
},
async takeOver(tripId: number | string, body: TourTakeOverRequest): Promise<TourCreateResponse> {
requireOnline();
const result = await tourLibraryApi.takeOver(tripId, body);
await cacheTourAnswer(Number(tripId), result);
return result;
},
};