feat(assistant): hike, walk and route cards with their lines on the map, and "Plan this"

This commit is contained in:
Maurice
2026-10-22 15:50:47 +02:00
parent 8547006742
commit 59313dfaff
135 changed files with 12185 additions and 234 deletions
@@ -27,17 +27,23 @@ function endName(stop: number | undefined, t: Translate): string {
return stop === undefined ? t('tours.planner.shapingPoint') : t('tours.planner.waypointLabel', { n: stop });
}
/** How another way differs from the one taken now, in length and time; nothing it cannot say. */
function VariantDelta({
/**
* How another way differs from the one taken now, in length and time; nothing
* it cannot say. `hint` names what it is compared with, the way taken now
* unless said otherwise.
*/
export function VariantDelta({
variant,
current,
unit,
t,
hint,
}: {
variant: LegVariant;
current: LegVariant;
unit: DistanceUnit;
t: Translate;
hint?: string;
}) {
const delta = variantDelta(variant, current);
const parts = [
@@ -51,7 +57,7 @@ function VariantDelta({
].filter((part) => part.text !== null);
if (parts.length === 0) return null;
return (
<Tooltip label={t('tours.variants.deltaHint')}>
<Tooltip label={hint ?? t('tours.variants.deltaHint')}>
<span className="flex flex-wrap gap-1" data-testid="leg-variant-delta">
{parts.map(({ key, Icon, text }) => (
<SoftPill key={key} icon={<Icon size={10} strokeWidth={2.2} aria-hidden="true" />}>
@@ -5,7 +5,7 @@ import type { Day } from '../../../types'
import { useTranslation } from '../../../i18n'
import { useSettingsStore } from '../../../store/settingsStore'
import { useTourFerrataCrossingStore } from '../../../store/tourFerrataCrossingStore'
import { formatDistance, formatElevation } from '../../../utils/units'
import { formatDistance } from '../../../utils/units'
import ConfirmDialog from '../../shared/ConfirmDialog'
import { NEUTRAL_TINT, fs } from '../../shared/DialogShell'
import EmptyState from '../../shared/EmptyState'
@@ -15,7 +15,7 @@ import { BOX } from '../../Planner/bookings/bookingParts'
import { BarButton, SoftPill } from '../../Planner/planParts'
import TourListRow from '../TourListRow'
import ElevationProfile from '../../shared/ElevationProfile'
import { formatPlannedTourDuration, hikeSourceBadgeLabel, tourSource } from '../tourPresentation'
import { formatPlannedTourDuration, hikeSourceBadgeLabel, profileFocusLabel, tourSource } from '../tourPresentation'
import { CardAction, FoldButton, RailCard, RailFacts, TourDayMenu, TourListCard, TourNotice, TourSection, type TourMetricField } from '../tourParts'
import { movingTimeLabel, tourMetricFacts, withoutHeights } from '../tourFacts'
import { TourDetailsSection, TourNameField } from './TourEditorFields'
@@ -40,7 +40,7 @@ import { stageKeysOfTour } from '../stages/stageSpread'
import { TourStageOverview } from '../stages/TourStageOverview'
import { useTourStageRail } from '../stages/useTourStageRail'
import { useTripStore } from '../../../store/tripStore'
import type { DistanceIndexedProfileSample, RouteProfileFocus } from '../../../utils/routeGeometry'
import type { DistanceIndexedProfileSample } from '../../../utils/routeGeometry'
import type { TourPlannerController } from './useTourPlanner'
import { RailStatusBadges } from './TourRailStatus'
import type { Translate } from './railStatusText'
@@ -76,13 +76,6 @@ import { walkTimeFields } from '../walk/walkTimeFields'
/** The tinted head band both rails open with, like every panel head in the planner. */
export const RAIL_HEAD = 'flex flex-none items-start gap-2 border-b border-edge-faint px-3 py-2.5'
function profileFocusLabel(focus: RouteProfileFocus, t: Translate, unit: 'metric' | 'imperial'): string {
return t('tours.planner.inspector.profileFocus', {
distance: formatDistance(focus.distanceMeters / 1000, unit),
elevation: focus.elevationMeters == null ? '-' : formatElevation(focus.elevationMeters, unit),
})
}
/** The title of a rail's head band, with an optional line under it. */
export function RailTitle({ title, sub, aside }: { title: string; sub?: ReactNode; aside?: ReactNode }) {
return (
@@ -1,9 +1,9 @@
// FE-TOUR-LEG-VARIANT-PAINT-001 to FE-TOUR-LEG-VARIANT-PAINT-004: the ways of a compared section
// FE-TOUR-LEG-VARIANT-PAINT-001 to FE-TOUR-LEG-VARIANT-PAINT-005: the ways of a compared section
// and the round hikes offered on the planner map, each in its colour, the one in focus on top
// (RTE-02, RTE-03).
import { renderHook } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { drawOrder, useLegVariantLines, variantPaintCss } from './legVariantPaint';
import { drawOrder, useLegVariantLines, useVariantPaint, variantPaintCss } from './legVariantPaint';
import type { LegVariant } from './legVariants';
const variant = (key: LegVariant['key'], lat: number): LegVariant => ({
@@ -87,4 +87,15 @@ describe('legVariantPaint', () => {
const empty = renderHook(() => useLegVariantLines([], null, null, rounds, null));
expect(empty.result.current.route).toEqual([WAYS[1].coordinates, WAYS[2].coordinates]);
});
it('FE-TOUR-LEG-VARIANT-PAINT-005: hands the colours of the ways and their rim resolved, for a map outside the planner', () => {
const { result } = renderHook(() => useVariantPaint());
expect(result.current).toEqual({
current: '#0a84ff',
a: '#f97316',
b: '#d946ef',
c: '#14b8a6',
casing: '#ffffff',
});
});
});
@@ -23,6 +23,11 @@ export function variantPaintCss(key: LegVariantKey): string {
return `var(${VARIANT_PAINT_TOKENS[key]})`;
}
/** The ways' colours and their rim resolved for map paint, again whenever the theme changes. */
export function useVariantPaint(): Readonly<Record<LegVariantKey | 'casing', string>> {
return useMapPaint(VARIANT_PAINT_TOKENS);
}
type Drawn = Parameters<typeof withRouteHighlight>;
/** A way as the map draws it: its line and the key its colour goes by. */
type DrawnWay = Pick<LegVariant, 'key' | 'coordinates'>;
@@ -60,7 +65,7 @@ export function useLegVariantLines(
variants: readonly DrawnWay[] | null,
focus: LegVariantKey | null
) {
const paint = useMapPaint(VARIANT_PAINT_TOKENS);
const paint = useVariantPaint();
return useMemo(() => {
const ordered = variants ? drawOrder(variants, focus) : [];
const highlight = ordered.length
@@ -48,7 +48,7 @@ export function StopDisc({ stop }: { stop: number | undefined }) {
* the route's own icon, the others by their letter. The chosen one carries a
* tick at its corner.
*/
function VariantMark({ variant, chosen }: { variant: Pick<LegVariant, 'key' | 'current'>; chosen: boolean }) {
export function VariantMark({ variant, chosen }: { variant: Pick<LegVariant, 'key' | 'current'>; chosen: boolean }) {
return (
<span
className="relative grid h-7 w-7 flex-none place-items-center rounded-full font-geist font-bold uppercase shadow-sm"