mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 15:36:33 +00:00
03d6457bde
PAD-05B: a click on an obstacle on the map or on the route band opens its card in the look of the via ferrata card: the kind with its glyph, the name, how it stands to the route (on it at a distance along it, near it with the link marked unclear, or only in the area), the paddling rule its tags give with canoe read before boat, a condition as written, height, grade, hours and fees, the source with the date of the data and the OpenStreetMap link. A missing rule reads as unknown, never as allowed, and a portage way recorded as private says so. Objects only in the area show from zoom 13 on, on Leaflet and GL alike; on GL the lines only near the route are dashed as on Leaflet, one click handler picks the marker over the line, and a picked marker no longer flickers. The route band marks the obstacles on and near the route by their share of the measured line. The obstacle notice also names an answer cut at its limit. PAD-05A: the admin area gets a Paddle water data card under the addons, on desktop and phone: a search in Geofabrik's list with each region's path, the regions with their state (waiting, reading with its progress, ready with objects and data date, failed with the reason), reading again and removing after a confirmation. The list follows a read without reloading. Region changes write audit rows. Map colours of paddle objects and portages come from theme tokens read at draw time, as the via ferratas do; the ferrata layer now shares that reader. The rail takes the planner page's parts as one bag, the map hit tests of the tour layers are one helper, and the unused noWaterData string is gone from every locale.
109 lines
3.5 KiB
TypeScript
109 lines
3.5 KiB
TypeScript
import type { PaddleLock, TrackMarks } from '@trek/shared';
|
|
import { create } from 'zustand';
|
|
import {
|
|
NO_TRACK_MARKS,
|
|
withLock,
|
|
withLockTimes,
|
|
withoutPortage,
|
|
withPortage,
|
|
withPortageExtra,
|
|
} from '../utils/paddleTrackMarks';
|
|
|
|
/** What a click on the recorded track does next: nothing, mark a lock, or one end of a portage. */
|
|
export type TrackPick = 'lock' | 'portage' | null;
|
|
|
|
export interface TrackSpeeds {
|
|
paddle: number | null;
|
|
portage: number | null;
|
|
}
|
|
|
|
interface TrackMarkToolState {
|
|
/** The tour the marks below belong to; null while no recorded paddle track is open. */
|
|
placeId: number | null;
|
|
/** The marks as they are being laid, not yet saved. */
|
|
marks: TrackMarks;
|
|
speeds: TrackSpeeds;
|
|
/** Whether anything changed since they were loaded or saved. */
|
|
dirty: boolean;
|
|
pick: TrackPick;
|
|
/** Where the portage being marked starts, once its first end is set. */
|
|
pendingFromM: number | null;
|
|
/** The last click was on a portage already there, or off the line: the hint says so. */
|
|
refused: 'overlap' | 'off_line' | null;
|
|
}
|
|
|
|
function initial(): TrackMarkToolState {
|
|
return {
|
|
placeId: null,
|
|
marks: NO_TRACK_MARKS,
|
|
speeds: { paddle: null, portage: null },
|
|
dirty: false,
|
|
pick: null,
|
|
pendingFromM: null,
|
|
refused: null,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* PAD-03 for a recorded paddle track: the marks being laid onto it, shared by
|
|
* the rail that lists them and the map that is clicked to place them. A click
|
|
* on the line gives a distance along it; a lock takes one, a portage two.
|
|
*/
|
|
export const useTrackMarkToolStore = create<TrackMarkToolState>(() => initial());
|
|
|
|
const set = useTrackMarkToolStore.setState;
|
|
|
|
export function loadTrackMarks(
|
|
placeId: number | null,
|
|
marks: TrackMarks | null | undefined,
|
|
speeds: TrackSpeeds
|
|
): void {
|
|
set({ ...initial(), placeId, marks: marks ?? NO_TRACK_MARKS, speeds });
|
|
}
|
|
|
|
export function startTrackPick(pick: TrackPick): void {
|
|
set({ pick, pendingFromM: null, refused: null });
|
|
}
|
|
|
|
/** A click on the line at this distance along it, for the tool that is on. */
|
|
export function pickOnTrack(atM: number): void {
|
|
const { pick, pendingFromM, marks } = useTrackMarkToolStore.getState();
|
|
if (pick === 'lock') {
|
|
set({ marks: withLock(marks, atM), dirty: true, pick: null, refused: null });
|
|
return;
|
|
}
|
|
if (pick !== 'portage') return;
|
|
if (pendingFromM === null) {
|
|
set({ pendingFromM: atM, refused: null });
|
|
return;
|
|
}
|
|
const next = withPortage(marks, pendingFromM, atM);
|
|
if (next === marks) {
|
|
set({ refused: 'overlap', pendingFromM: null });
|
|
return;
|
|
}
|
|
set({ marks: next, dirty: true, pick: null, pendingFromM: null, refused: null });
|
|
}
|
|
|
|
export function refuseTrackPick(): void {
|
|
set({ refused: 'off_line' });
|
|
}
|
|
|
|
function edit(marks: TrackMarks): void {
|
|
set({ marks, dirty: true });
|
|
}
|
|
|
|
export const trackMarkEdits = {
|
|
removePortage: (index: number) => edit(withoutPortage(useTrackMarkToolStore.getState().marks, index)),
|
|
setPortageExtra: (index: number, minutes: number | null) =>
|
|
edit(withPortageExtra(useTrackMarkToolStore.getState().marks, index, minutes)),
|
|
setLock: (index: number, lock: PaddleLock | null) =>
|
|
edit(withLockTimes(useTrackMarkToolStore.getState().marks, index, lock)),
|
|
setSpeeds: (speeds: Partial<TrackSpeeds>) =>
|
|
set((state) => ({ speeds: { ...state.speeds, ...speeds }, dirty: true })),
|
|
};
|
|
|
|
export function markTrackMarksSaved(marks: TrackMarks | null | undefined, speeds: TrackSpeeds): void {
|
|
set({ marks: marks ?? NO_TRACK_MARKS, speeds, dirty: false, pick: null, pendingFromM: null, refused: null });
|
|
}
|