mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +00:00
2c3b20bb57
PAD-03 portages and locks on planned tours and recorded tracks, PAD-07 paddle time with portage and lock stops, PAD-08 wind forecast for the start, PAD-05A regional obstacle import from Geofabrik extracts with admin endpoints and a monthly refresh, PAD-05B first cut of the obstacle layer on Leaflet, GL and 3D. Work in progress: checklist (PAD-06), check bench (PAD-09), admin UI, translations and tests follow.
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import type { PaddleCoverageRegion, PaddleCoverageState, PaddleFeature, RelatedObstacle } from '@trek/shared';
|
|
import { create } from 'zustand';
|
|
|
|
/** Whether the obstacles around the open paddle tour are there to show, and if not, why. */
|
|
export type PaddleObstacleStatus = 'idle' | 'loading' | 'ready' | 'offline' | 'error';
|
|
|
|
interface PaddleObstacleState {
|
|
status: PaddleObstacleStatus;
|
|
/** Every object read around the route. */
|
|
features: PaddleFeature[];
|
|
/** The ones on or near the route, in the order the route reaches them. */
|
|
related: RelatedObstacle[];
|
|
coverage: PaddleCoverageState;
|
|
regions: PaddleCoverageRegion[];
|
|
truncated: boolean;
|
|
/** The object whose card is open, by OSM reference; the map and the checklist show the same one. */
|
|
selectedRef: string | null;
|
|
}
|
|
|
|
const EMPTY: PaddleObstacleState = {
|
|
status: 'idle',
|
|
features: [],
|
|
related: [],
|
|
coverage: 'none',
|
|
regions: [],
|
|
truncated: false,
|
|
selectedRef: null,
|
|
};
|
|
|
|
/**
|
|
* PAD-05B: the paddle obstacles of the tour open in the planner, shared by
|
|
* the map that draws them and the rails that list them. One sync hook writes
|
|
* it; everything else reads.
|
|
*/
|
|
export const usePaddleObstacleStore = create<PaddleObstacleState>(() => EMPTY);
|
|
|
|
export function publishPaddleObstacles(next: Omit<PaddleObstacleState, 'selectedRef'>): void {
|
|
usePaddleObstacleStore.setState((state) => ({
|
|
...next,
|
|
// A selection that is no longer among the objects is dropped with them.
|
|
selectedRef: next.features.some((feature) => feature.ref === state.selectedRef) ? state.selectedRef : null,
|
|
}));
|
|
}
|
|
|
|
export function selectPaddleObstacle(ref: string | null): void {
|
|
usePaddleObstacleStore.setState({ selectedRef: ref });
|
|
}
|
|
|
|
export function clearPaddleObstacles(): void {
|
|
usePaddleObstacleStore.setState(EMPTY);
|
|
}
|