mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
1bc82f97fd
Paddle tours are planned on the water by TREK's own router: a water network per paddle region, built from the same Geofabrik extract as the obstacles and searched in a worker thread of the server (no sidecar). Rivers, canals and lakes (direct or along the shore), portages round weirs, locks by policy, whitewater by boat, gaps marked. Found portages and locks become points of their own; an unplannable leg says why and offers a way out. - Shaping points: a click on the line sets a point that steers the route without being a stop (hikes and paddle tours); recompute a single leg. - Lake style direct/shore, suggested from the wind forecast. - Regions load by themselves where a paddler plans (admin setting: automatic, on request, off; size cap and a daily count), with requests for the admins, a notification, and the load followed on the leg. - Portage from the last point, portages follow footways via the walking router (or stay straight), "put in here" on slipways and put-ins. - MCP plan_paddle_route with the REST route's rules.
38 lines
1.7 KiB
TypeScript
38 lines
1.7 KiB
TypeScript
import { paddleRegionsApi } from '../api/paddleRegions';
|
|
import { isEffectivelyOffline } from '../sync/networkMode';
|
|
|
|
/** Thrown instead of asking while the app is offline, so the view can say so rather than show a failure. */
|
|
export class PaddleRegionsOfflineError extends Error {
|
|
constructor() {
|
|
super('Paddle regions are managed with a connection only');
|
|
this.name = 'PaddleRegionsOfflineError';
|
|
}
|
|
}
|
|
|
|
function online<A extends unknown[], R>(call: (...args: A) => Promise<R>): (...args: A) => Promise<R> {
|
|
return (...args) => (isEffectivelyOffline() ? Promise.reject(new PaddleRegionsOfflineError()) : call(...args));
|
|
}
|
|
|
|
/** Why a region call was refused, from the code the server puts next to its error. */
|
|
export function paddleRegionErrorCode(err: unknown): 'offline' | 'catalog_unavailable' | 'unknown_region' | null {
|
|
if (err instanceof PaddleRegionsOfflineError) return 'offline';
|
|
const code = (err as { response?: { data?: { code?: unknown } } } | null)?.response?.data?.code;
|
|
return code === 'catalog_unavailable' || code === 'unknown_region' ? code : null;
|
|
}
|
|
|
|
/**
|
|
* PAD-05A: the instance's paddle regions. Online only on purpose: they are
|
|
* instance administration, and a queued add or remove replayed later could
|
|
* undo what another admin decided meanwhile.
|
|
*/
|
|
export const paddleRegionRepo = {
|
|
list: online(paddleRegionsApi.list),
|
|
catalog: online(paddleRegionsApi.catalog),
|
|
add: online(paddleRegionsApi.add),
|
|
refresh: online(paddleRegionsApi.refresh),
|
|
remove: online(paddleRegionsApi.remove),
|
|
decline: online(paddleRegionsApi.decline),
|
|
settings: online(paddleRegionsApi.settings),
|
|
saveSettings: online(paddleRegionsApi.saveSettings),
|
|
};
|