feat(tours): route paddle tours on the water, shaping points and auto-loaded regions

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.
This commit is contained in:
Maurice
2026-10-18 01:13:24 +02:00
parent b76a298bb3
commit 1bc82f97fd
321 changed files with 14675 additions and 471 deletions
@@ -0,0 +1,130 @@
import type { PaddleRegionLoadState } from '@trek/shared';
import { CloudDownload, Hourglass, Loader2, Spline } from 'lucide-react';
import { useTranslation } from '../../../i18n';
import { fs } from '../../shared/DialogShell';
type Translate = ReturnType<typeof useTranslation>['t'];
/** The states in which the data is on its way: the leg waits rather than fails. */
export function isRegionLoadPending(
state: PaddleRegionLoadState | undefined
): state is Extract<PaddleRegionLoadState, { state: 'loading' | 'ready' | 'requested' }> {
return state?.state === 'loading' || state?.state === 'ready' || state?.state === 'requested';
}
/**
* Why a leg stays unplanned once the data cannot come: declined, failed, no
* water near the place, nothing to load. Null where the leg's own reason says
* it best (loading is off, or nothing was asked yet).
*/
export function regionLoadFailure(state: PaddleRegionLoadState | undefined, t: Translate): string | null {
if (!state) return null;
const region = state.region?.name ?? '';
switch (state.state) {
case 'declined':
return t('tours.paddle.load.declined', { region });
case 'failed':
return t('tours.paddle.load.failed', { region });
case 'no_water':
return t('tours.paddle.load.noWater', { region });
case 'unavailable':
if (state.reason === 'no_extract') return t('tours.paddle.load.noExtract');
if (state.reason === 'catalog_unavailable') return t('tours.paddle.load.catalogUnavailable');
return null;
default:
return null;
}
}
function headline(state: Extract<PaddleRegionLoadState, { state: 'loading' | 'ready' | 'requested' }>, t: Translate) {
const region = state.region.name;
if (state.state === 'ready') return t('tours.paddle.load.ready', { region });
if (state.state === 'requested') return t('tours.paddle.load.requested', { region });
return t('tours.paddle.load.loading', { region });
}
/** The phase of a load in words, with its share where it is known. */
function phaseText(state: Extract<PaddleRegionLoadState, { state: 'loading' }>, t: Translate, language: string) {
if (!state.progress) return state.ahead > 0 ? t('tours.paddle.load.waiting') : t('tours.paddle.load.phase.download');
const phase = t(`tours.paddle.load.phase.${state.progress.phase}`);
const share = state.progress.fraction;
return share === null ? phase : `${phase} ${new Intl.NumberFormat(language, { style: 'percent' }).format(share)}`;
}
/**
* PAD-11C: a leg waiting for the water data of its region, which TREK loads
* by itself or an admin has to let through. Calm, not red: nothing is wrong,
* the data is on its way, and the leg is planned on its own once it is there.
* Drawing it straight stays possible for whoever does not want to wait.
*/
export function PaddleRegionLoadRow({
state,
disabled,
onDrawStraight,
}: {
state: Extract<PaddleRegionLoadState, { state: 'loading' | 'ready' | 'requested' }>;
disabled: boolean;
onDrawStraight: () => void;
}) {
const { t, language } = useTranslation();
const fraction = state.state === 'loading' ? (state.progress?.fraction ?? null) : state.state === 'ready' ? 1 : null;
const busy = state.state !== 'requested';
return (
<li data-testid="tour-planner-region-load" className="flex min-w-0 py-0.5 ps-[34px]">
<div
role="status"
className="flex w-full min-w-0 flex-col gap-1.5 rounded-[10px] bg-surface-secondary px-2 py-1.5 ring-1 ring-inset ring-edge-faint"
>
<span className="flex min-w-0 items-start gap-1.5 font-semibold text-content" style={fs(11.5, 'body')}>
{busy ? (
<Loader2 size={12} strokeWidth={2.2} className="mt-[2px] flex-none animate-spin" aria-hidden="true" />
) : (
<Hourglass size={12} strokeWidth={2.2} className="mt-[2px] flex-none" aria-hidden="true" />
)}
<span className="min-w-0">{headline(state, t)}</span>
</span>
{state.state === 'loading' && (
<span className="flex min-w-0 flex-col gap-1">
<span className="flex items-center justify-between gap-2 text-content-muted" style={fs(10.5, 'body')}>
<span className="inline-flex min-w-0 items-center gap-1">
<CloudDownload size={11} strokeWidth={2.2} className="flex-none" aria-hidden="true" />
<span className="truncate">{phaseText(state, t, language)}</span>
</span>
</span>
<span
className="relative block h-[3px] w-full overflow-hidden rounded-full bg-surface-tertiary"
aria-hidden="true"
>
<span
className={`absolute inset-y-0 start-0 rounded-full bg-accent transition-[width] duration-500 ${fraction === null ? 'w-1/3 animate-pulse' : ''}`}
style={fraction === null ? undefined : { width: `${Math.max(4, Math.round(fraction * 100))}%` }}
/>
</span>
<span className="leading-snug text-content-faint" style={fs(10.5, 'body')}>
{t('tours.paddle.load.hint')}
</span>
</span>
)}
{state.state === 'requested' && state.reason !== 'ask' && (
<span className="leading-snug text-content-muted" style={fs(10.5, 'body')}>
{t(state.reason === 'too_large' ? 'tours.paddle.load.reason.tooLarge' : 'tours.paddle.load.reason.limit')}
</span>
)}
{state.state !== 'ready' && (
<span className="flex flex-wrap gap-1">
<button
type="button"
disabled={disabled}
onClick={onDrawStraight}
className="inline-flex h-[22px] flex-none items-center gap-1 rounded-full bg-surface-card px-2 font-semibold text-content shadow-sm ring-1 ring-inset ring-edge-faint transition-colors hover:bg-surface-hover disabled:opacity-40"
style={fs(10.5)}
>
<Spline size={11} strokeWidth={2.2} aria-hidden="true" />
{t('tours.paddle.drawStraight')}
</button>
</span>
)}
</div>
</li>
);
}