feat(tours): bike tours in the planner, CyclOSM, and the planned cards' last points (BIK-01 to BIK-06, RTE-01, IO-01, LIB-02)

The tour type is a dropdown; a bike tour picks its profile, routes for it,
says when a point lies off every way, and shows what it runs on: surfaces,
kinds of way and, for a mountain bike, the trail grades, each pointed at on
the map. A type's own map (OpenHikingMap for a hike, CyclOSM for a bike tour)
is offered while a tour of that type is open, with an admin switch each.

From the planned cards: a hike avoids steep climbs, steps or ferries, nothing
else; a saved tour can be shared where the platform takes GPX files; and the
tours rail adds a tour from one menu: plan new, import GPX, or take one over
from another trip.
This commit is contained in:
Maurice
2026-10-19 21:33:49 +02:00
parent adcaca3c5f
commit 73237ffedb
85 changed files with 3728 additions and 647 deletions
@@ -561,15 +561,20 @@ describe('TourPlannerMapStage', () => {
]);
});
it('an imported paddle tour is shown with the paddle maps, a type nobody plans with the standard set', () => {
it('an imported paddle tour is shown with the paddle maps, a bike tour with its own, a type nobody plans with the standard set', () => {
const { unmount } = renderStage(
planner('view-gpx', { mode: { type: 'view-gpx', placeId: 9, tour: { place_id: 9, tour_type: 'kayak' } } })
);
expect(flat().tourLayers?.bases).toEqual(['default', 'satellite']);
unmount();
renderStage(
const bike = renderStage(
planner('view-gpx', { mode: { type: 'view-gpx', placeId: 9, tour: { place_id: 9, tour_type: 'bike' } } })
);
expect(flat().tourLayers?.bases).toEqual(['default', 'topo', 'satellite']);
bike.unmount();
renderStage(
planner('view-gpx', { mode: { type: 'view-gpx', placeId: 9, tour: { place_id: 9, tour_type: 'run' } } })
);
expect(flat().tourLayers?.bases).toEqual(['default', 'satellite']);
expect(flat().tourLayers?.overlays).toEqual([]);
expect(flat().ferrataLayer).toBeUndefined();
@@ -10,26 +10,34 @@ type Ferrata = Parameters<typeof useTourStageLayers>[1];
const ferrata = { layer: undefined, crossings: [], selected: null } as unknown as Ferrata;
function planner(mode: TourPlannerController['mode'], tourType: Planner['tourType'] = 'hike'): Planner {
return { mode, tourType, mapBaseLayer: 'hiking', mapOverlays: new Set(), toggleMapOverlay: () => {} };
function planner(
mode: TourPlannerController['mode'],
tourType: Planner['tourType'] = 'hike',
mapBaseLayer: Planner['mapBaseLayer'] = 'hiking'
): Planner {
return { mode, tourType, mapBaseLayer, mapOverlays: new Set(), toggleMapOverlay: () => {} };
}
const basesOf = (p: Planner) => renderHook(() => useTourStageLayers(p, ferrata)).result.current;
describe('useTourStageLayers: OpenHikingMap (MAP-01)', () => {
beforeEach(() => useAddonStore.setState({ toursHikingMap: true }));
beforeEach(() => useAddonStore.setState({ toursHikingMap: true, toursCycleMap: true }));
it('offers it while a hike is planned, as a draft or a saved tour in the editor', () => {
for (const mode of [{ type: 'new-draft' }, { type: 'edit-saved', placeId: 4 }] as const) {
it('offers it while a hike is open: planned as a draft, a saved tour in the editor, or an import viewed as it came in', () => {
const viewed = { type: 'view-gpx', placeId: 9, tour: { place_id: 9, tour_type: 'hike' } as TourListItem } as const;
for (const mode of [{ type: 'new-draft' }, { type: 'edit-saved', placeId: 4 }, viewed] as const) {
const layers = basesOf(planner(mode));
expect(layers.tourLayers.bases).toContain('hiking');
expect(layers.baseLayer).toBe('hiking');
}
});
it('not with no tour open, over an import viewed as it came in, or for a paddle tour', () => {
const viewed = { type: 'view-gpx', placeId: 9, tour: { place_id: 9, tour_type: 'hike' } as TourListItem } as const;
for (const p of [planner({ type: 'neutral' }), planner(viewed), planner({ type: 'new-draft' }, 'kayak')]) {
it('not with no tour open, or for a paddle or a bike tour', () => {
for (const p of [
planner({ type: 'neutral' }),
planner({ type: 'new-draft' }, 'kayak'),
planner({ type: 'new-draft' }, 'bike'),
]) {
const layers = basesOf(p);
expect(layers.tourLayers.bases).not.toContain('hiking');
// The choice is kept; the map shows the type's default until a hike is planned again.
@@ -41,4 +49,17 @@ describe('useTourStageLayers: OpenHikingMap (MAP-01)', () => {
useAddonStore.setState({ toursHikingMap: false });
expect(basesOf(planner({ type: 'new-draft' })).tourLayers.bases).not.toContain('hiking');
});
it('BIK-06: CyclOSM for a bike tour that is open, watched for whether it answers, and only while the admin allows it', () => {
const viewed = { type: 'view-gpx', placeId: 9, tour: { place_id: 9, tour_type: 'bike' } as TourListItem } as const;
for (const mode of [{ type: 'new-draft' }, viewed] as const) {
const layers = basesOf(planner(mode, 'bike', 'cycle'));
expect(layers.tourLayers.bases).toEqual(['default', 'topo', 'cycle', 'satellite']);
expect(layers.baseLayer).toBe('cycle');
expect(layers.tourLayers.baseHealth).toMatchObject({ base: 'cycle', down: false });
}
expect(basesOf(planner({ type: 'new-draft' }, 'hike', 'cycle')).baseLayer).toBe('default');
useAddonStore.setState({ toursCycleMap: false });
expect(basesOf(planner({ type: 'new-draft' }, 'bike', 'cycle')).tourLayers.bases).not.toContain('cycle');
});
});
@@ -1,11 +1,11 @@
import { useCallback, useEffect, useMemo } from 'react';
import { useCallback, useMemo } from 'react';
import { useShallow } from 'zustand/react/shallow';
import type { useFerrataMapLayer } from '../../components/Ferratas/useFerrataMapLayer';
import { paddleMapItems, selectedPaddleKey } from '../../components/Tours/paddle/paddleMapLayer';
import { usePaddlePaint } from '../../components/Tours/paddle/paddlePaint';
import type { TourPlannerController } from '../../components/Tours/planner/useTourPlanner';
import { baseLayerFor, SEAMARK_OVERLAY, tourMapLayersFor } from '../../components/Tours/tourMapLayers';
import { useTileHealth, useTourRasterOverlay } from '../../components/Tours/useTourRasterOverlay';
import { useBaseMapHealth, useTourRasterOverlay } from '../../components/Tours/useTourRasterOverlay';
import { useAddonStore } from '../../store/addonStore';
import { selectPaddleObstacle, usePaddleObstacleStore } from '../../store/paddleObstacleStore';
@@ -26,21 +26,18 @@ export function useTourStageLayers(
ferrata: FerrataLayerState
) {
const { mode } = tourPlanner;
// MAP-01: OpenHikingMap while a hike is being planned (a draft or a saved tour in the editor),
// never over an import viewed as it came in or with no tour open, and only while the admin offers it.
// MAP-01, BIK-06: a type's own map (OpenHikingMap for a hike, CyclOSM for a bike tour) while a
// tour of that type is open, planned or viewed as it came in, never with no tour open, and only
// while the admin offers it.
const hikingMapAllowed = useAddonStore((state) => state.toursHikingMap);
const planning = mode.type === 'new-draft' || mode.type === 'edit-saved';
const cycleMapAllowed = useAddonStore((state) => state.toursCycleMap);
const tourOpen = mode.type !== 'neutral';
const layerSet = tourMapLayersFor(mode.type === 'view-gpx' ? mode.tour.tour_type : tourPlanner.tourType, {
hikingMap: hikingMapAllowed && planning,
hikingMap: hikingMapAllowed && tourOpen,
cycleMap: cycleMapAllowed && tourOpen,
});
const baseLayer = baseLayerFor(layerSet, tourPlanner.mapBaseLayer);
// Whether OpenHikingMap answers, asked afresh each time it becomes the base map.
const hikingMap = useTileHealth();
const { reset: resetHikingMap } = hikingMap;
const showsHikingMap = baseLayer === 'hiking';
useEffect(() => {
if (showsHikingMap) resetHikingMap();
}, [showsHikingMap, resetHikingMap]);
const baseHealth = useBaseMapHealth(baseLayer);
// With no tour open nothing is a hike yet: the ferratas wait for one, as the seamarks wait for a paddle tour.
const offersFerratas = mode.type !== 'neutral' && layerSet.overlays.includes('ferratas');
const { toggleMapOverlay } = tourPlanner;
@@ -74,9 +71,9 @@ export function useTourStageLayers(
bases: layerSet.bases,
overlays: layerSet.overlays.includes('seamarks') ? [seamarks] : [],
paddle,
hikingMap: showsHikingMap ? hikingMap : undefined,
baseHealth,
}),
[layerSet, seamarks, paddle, showsHikingMap, hikingMap]
[layerSet, seamarks, paddle, baseHealth]
);
return {
baseLayer,
@@ -8,6 +8,7 @@ import { usePaddleObstacleSync } from '../../components/Tours/paddle/usePaddleOb
import { tourPlannedTimes as projectTourPlannedTimes } from '../../components/Tours/tourPresentation'
import { usePlanMapViewport } from '../../hooks/usePlanMapViewport'
import { usePaddleObstacleStore } from '../../store/paddleObstacleStore'
import { useHighlightedRoute } from '../../components/Tours/bike/useHighlightedRoute'
import { useMapLocationSearch } from './useMapLocationSearch'
import { usePlannerFocusPoints } from './usePlannerFocusPoints'
import { useTripPlanner } from './useTripPlanner'
@@ -75,6 +76,8 @@ export function useTripPlannerPage() {
{ portage: paddlePaint.portage, rapids: paddlePaint.rapids, gap: paddlePaint.gap, casing: paddlePaint.disc },
)
const routeWalking = partStyle.walking ?? (route && route.length === 2 && tourConversion.line ? [true, false] : null)
// BIK-01 to BIK-05: the stretches a bike tour's card points at, over the route being edited.
const drawn = useHighlightedRoute(editingRoute && !wandererBrowser.open, route, routeWalking, partStyle.colors)
const { closeGpxTour } = tourPlanner
useEffect(() => {
@@ -116,9 +119,9 @@ export function useTripPlannerPage() {
trackPaddlePlan,
paddleChecklist,
tourDetailActions,
tourMap: { route,
routeWalking,
routeColors: partStyle.colors,
tourMap: { route: drawn.route,
routeWalking: drawn.walking,
routeColors: drawn.colors,
previewPoints: tourConversion.status === 'idle' ? null : tourConversion.points,
focusPoints: mapFocusPoints,
// A picked wanderer trail frames itself; the rest follows the planner.