Files
TREK/client/src/repo/tourLibraryRepo.ts
T
Maurice 827e682684 feat(tours): places along the tour, and a found place as a stop (PLN-02, PLN-03)
The editor gains a card under the waypoints: along the tour. It offers what
the tour type stops for as chips (a hike viewpoints, huts and shelters,
drinking water, food, summits, toilets, picnic spots, campsites, sights; a
paddle tour put-ins, boat rental and the like, the first three ticked) and
how far from the route to look, 250 m to 2 km. Only its button searches.
Each place found shows how far it lies from the route, straight across, and
where along the route; its pin is on the map in its category's colour, and
a click there opens it in the card. Opened, a place says its kind and
source, its address, opening hours as the source has them with a note to
check them, and its website. The answer says when it is out of date (the
route or the choices changed since), offline, failed, partly searched, cut
short at the first part of a long tour, or more than shown. Nothing about
the tour changes by searching.

An opened place can go in as a stop: after the point chosen, the one before
it along the route suggested, by the button alone, as one step undo takes
back. It becomes a stop of the tour on the place's spot, not a place of the
trip. A leg drawn by hand or a fixed line (a via ferrata, a portage) is not
cut: the point after which it would go says why and offers no button. Once
the new route is in, the card says what the stop added, as the difference
of the route planned before and after; while it is planned it says so, and
where either route could not be planned it says that rather than guess.

The search merges a place OpenStreetMap maps twice, as a point and as its
outline, by its name and spot. The library repository takes its offline
error from a shared online-only module, which the search uses too.
2026-10-19 16:24:59 +02:00

37 lines
1.3 KiB
TypeScript

import type {
TourCreateResponse,
TourLibraryDetailResponse,
TourLibraryQuery,
TourLibraryResponse,
TourTakeOverRequest,
} from '@trek/shared';
import { tourLibraryApi } from '../api/tourLibrary';
import { cacheTourAnswer } from '../db/cacheTour';
import { requireOnline } from './onlineOnly';
/**
* 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;
},
};