feat(tours): plan ski and winter tours, snowshoeing and winter hiking among them

Ski becomes "Ski & winter", a type the planner plans with six disciplines
(alpine, snowboard, cross-country, ski touring, snowshoeing, winter hiking),
nothing preselected; saving needs a discipline, and a technique for
cross-country. Every leg is drawn straight between the points through
planner/skiRouting.ts, the one place the piste router will plug in, with its
heights from the elevation source and no ski time worked out.

The hike's winter label goes entirely: its migration, column, field, marks,
GPX rule, MCP field and strings. A hike is summer only; a ski tour with the
snowshoe discipline exports as snowshoeing. The unreleased ski migration takes
the six disciplines and the collection migration loses the winter column.

The pistes are offered for a ski tour, shown until switched off, and with no
tour open, never for a hike. Export, copy, collections, stages (untimed),
actual tracks, the atlas, list and day marks (one glyph per discipline), 3D,
planning over a ski import and list_tours/get_tour_plan know the planned ski
tour.
This commit is contained in:
Maurice
2026-10-20 18:27:53 +02:00
parent 204ee2ef86
commit 164a3633ac
116 changed files with 1675 additions and 1576 deletions
@@ -7,18 +7,22 @@ import { skiChoiceMissing, type SkiChoice } from './skiChoice';
import { SKI_DISCIPLINE_ICON } from './skiDiscipline';
/**
* SKI-02: what a ski track is, chosen on purpose: the discipline, none until
* one is picked, and for cross-country the technique, Unknown among its
* answers. The technique stays in sight but dimmed while another discipline
* is chosen. The info dot says what TREK does with the track. The GPX import
* and the classification dialog share it.
* SKI-02: what a ski tour is, chosen on purpose: the discipline, none until
* one is picked, six of them in two columns, and for cross-country the
* technique, Unknown among its answers. The technique stays in sight but
* dimmed while another discipline is chosen. The info dot says what TREK does
* with the tour. The GPX import, the classification dialog and the planner
* share it; `planned` says the choice is asked for a tour to save rather than
* a track to import.
*/
export function SkiClassificationFields({
choice,
onChange,
planned = false,
}: {
choice: SkiChoice;
onChange: (choice: SkiChoice) => void;
planned?: boolean;
}) {
const { t } = useTranslation();
const crossCountry = choice.discipline === 'cross_country';
@@ -34,13 +38,14 @@ export function SkiClassificationFields({
value={(choice.discipline ?? '') as SkiDiscipline}
onChange={(discipline) => onChange({ ...choice, discipline })}
label={t('tours.ski.discipline')}
fill
columns={2}
options={SKI_DISCIPLINES.map((discipline) => {
const Icon = SKI_DISCIPLINE_ICON[discipline];
return {
value: discipline,
label: t(`tours.ski.discipline.${discipline}`),
icon: <Icon size={13} strokeWidth={2} aria-hidden="true" />,
// Two columns in a narrow rail: a long name ends in an ellipsis rather than spilling out.
label: <span className="min-w-0 truncate">{t(`tours.ski.discipline.${discipline}`)}</span>,
icon: <Icon size={13} strokeWidth={2} aria-hidden="true" className="flex-none" />,
};
})}
/>
@@ -64,7 +69,13 @@ export function SkiClassificationFields({
</fieldset>
{missing && (
<TourNotice role="status" icon={<Info size={13} strokeWidth={2} />}>
{t(missing === 'discipline' ? 'tours.ski.chooseDiscipline' : 'tours.ski.chooseTechnique')}
{t(
missing === 'technique'
? 'tours.ski.chooseTechnique'
: planned
? 'tours.ski.chooseDisciplineToSave'
: 'tours.ski.chooseDiscipline'
)}
</TourNotice>
)}
</div>
@@ -1,11 +1,11 @@
import type { SkiDiscipline, SkiTechnique, TourListItem } from '@trek/shared';
import { CableCar, createLucideIcon, Spline, TrendingUp, type LucideIcon } from 'lucide-react';
import { CableCar, createLucideIcon, Footprints, Snowflake, Spline, TrendingUp, type LucideIcon } from 'lucide-react';
/**
* SKI-02: a snowboard seen from above, laid across the square with its two
* bindings. Lucide has no board, and the snowflake is the winter hike's mark
* (HIK-01): both sit in the same corner badge, so the board needs a glyph of
* its own to be told apart there.
* bindings. Lucide has no board, and the snowflake is the winter hike's mark:
* both sit in the same corner badge, so the board needs a glyph of its own to
* be told apart there.
*/
const BOARD = 'rotate(-45 12 12)';
const Snowboard = createLucideIcon('snowboard', [
@@ -15,26 +15,29 @@ const Snowboard = createLucideIcon('snowboard', [
]);
/**
* SKI-02: the icon each discipline goes by: a lift for alpine skiing, a board
* for snowboarding, a winding trail for cross-country and the climb on skins
* for ski touring. None of them is the winter hike's snowflake, which takes
* the same corner of a tile.
* SKI-02: the icon each discipline goes by, each its own: a lift for alpine
* skiing, a board for snowboarding, a winding trail for cross-country, the
* climb on skins for ski touring, footprints in the snow for snowshoeing and a
* snowflake for winter hiking. They all take the same corner of a tile, so no
* two share a glyph, and none is the tile's own mountain.
*/
export const SKI_DISCIPLINE_ICON: Record<SkiDiscipline, LucideIcon> = {
alpine: CableCar,
snowboard: Snowboard,
cross_country: Spline,
touring: TrendingUp,
snowshoe: Footprints,
winter_hike: Snowflake,
};
export type SkiTour = Partial<Pick<TourListItem, 'tour_type' | 'ski_discipline' | 'ski_technique'>>;
/** The discipline of a ski track, or null for any other tour and a ski track listed before it had one. */
/** The discipline of a ski tour, or null for any other tour and a ski track listed before it had one. */
export function skiDisciplineOf(tour: SkiTour): SkiDiscipline | null {
return tour.tour_type === 'ski' ? (tour.ski_discipline ?? null) : null;
}
/** A cross-country track's technique; null for every other discipline and type. */
/** A cross-country tour's technique; null for every other discipline and type. */
export function skiTechniqueOf(tour: SkiTour): SkiTechnique | null {
return skiDisciplineOf(tour) === 'cross_country' ? (tour.ski_technique ?? null) : null;
}
@@ -1,12 +1,12 @@
import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { TourDayRowAvatar } from '../TourDayRowFacts';
import { tourDayRowIcon } from '../tourDayRowIcon';
import { TourGradeTile } from '../tourParts';
import { WINTER_ACTIVITY_ICON } from '../winter/winterActivityIcon';
import { SKI_DISCIPLINE_ICON, skiClassificationText, skiDisciplineOf, skiTechniqueOf } from './skiDiscipline';
import { SkiCornerMark, SkiHeadPill } from './skiMarks';
// FE-TOUR-SKI-MARK-001 to FE-TOUR-SKI-MARK-006
// FE-TOUR-SKI-MARK-001 to FE-TOUR-SKI-MARK-007
const t = (key: string) => key;
const skiTrack = {
@@ -73,8 +73,22 @@ describe('ski marks (SKI-02)', () => {
expect(screen.getByTestId('tour-ski-mark')).toHaveStyle({ width: '22px' });
});
it('FE-TOUR-SKI-MARK-006: no discipline shares its corner glyph with another, nor with a winter label', () => {
const icons = [...Object.values(SKI_DISCIPLINE_ICON), ...Object.values(WINTER_ACTIVITY_ICON)];
it('FE-TOUR-SKI-MARK-006: each of the six disciplines has a corner glyph of its own, none the ski tile itself', () => {
const icons = Object.values(SKI_DISCIPLINE_ICON);
expect(icons).toHaveLength(6);
expect(new Set(icons).size).toBe(icons.length);
expect(icons).not.toContain(tourDayRowIcon('ski'));
});
it('FE-TOUR-SKI-MARK-007: snowshoeing and winter hiking are ski tours with their own marks, a hike carries none', () => {
const { rerender } = render(<SkiCornerMark tour={{ tour_type: 'ski', ski_discipline: 'snowshoe' }} />);
const snowshoe = screen.getByRole('img', { name: 'tours.ski.discipline.snowshoe' });
expect(snowshoe.querySelector('svg.lucide-footprints')).not.toBeNull();
rerender(<SkiCornerMark tour={{ tour_type: 'ski', ski_discipline: 'winter_hike' }} />);
const winterHike = screen.getByRole('img', { name: 'tours.ski.discipline.winter_hike' });
expect(winterHike.querySelector('svg.lucide-snowflake')).not.toBeNull();
const hike = { tour_type: 'hike' as const, max_hiking_difficulty: 2, wanderer_ref: null, has_waypoints: true };
render(<TourGradeTile tour={hike} />);
expect(screen.queryAllByTestId('tour-ski-mark')).toHaveLength(1);
});
});
+4 -4
View File
@@ -11,9 +11,9 @@ import {
} from './skiDiscipline';
/**
* SKI-02: a ski track's discipline on the corner of its round tile, a frosted
* badge carrying the discipline's icon, the way a hike carries its winter
* label there. Its tooltip names the discipline and a cross-country technique.
* SKI-02: a ski tour's discipline on the corner of its round tile, a frosted
* badge carrying the discipline's own icon. Its tooltip names the discipline
* and a cross-country technique.
*/
export function SkiCornerMark({ tour, size = 15 }: { tour: SkiTour; size?: number }) {
const { t } = useTranslation();
@@ -24,7 +24,7 @@ export function SkiCornerMark({ tour, size = 15 }: { tour: SkiTour; size?: numbe
}
/**
* SKI-02: a ski track's discipline as a pill of a tour's head, beside its
* SKI-02: a ski tour's discipline as a pill of a tour's head, beside its
* type, a cross-country technique as a badge inside it. The tooltip says what
* TREK does with the track and what it does not say.
*/
@@ -0,0 +1,30 @@
import { act, renderHook } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { NO_SKI_CHOICE } from './skiChoice';
import { useSkiFields } from './useSkiFields';
// FE-TOUR-SKI-FIELDS-001 to FE-TOUR-SKI-FIELDS-002
describe('useSkiFields (SKI-02)', () => {
it('FE-TOUR-SKI-FIELDS-001: a change is an edit only when it says something else and the planner allows it', () => {
const onEdit = vi.fn(() => true);
const { result } = renderHook(() => useSkiFields(NO_SKI_CHOICE, onEdit));
act(() => result.current.change({ discipline: null, technique: null }));
expect(onEdit).not.toHaveBeenCalled();
act(() => result.current.change({ discipline: 'snowshoe', technique: null }));
expect(onEdit).toHaveBeenCalledTimes(1);
expect(result.current.choice).toEqual({ discipline: 'snowshoe', technique: null });
onEdit.mockReturnValue(false);
act(() => result.current.change({ discipline: 'alpine', technique: null }));
expect(result.current.choice).toEqual({ discipline: 'snowshoe', technique: null });
});
it('FE-TOUR-SKI-FIELDS-002: a choice loaded from a tour or a draft is no edit', () => {
const onEdit = vi.fn(() => true);
const { result } = renderHook(() => useSkiFields(NO_SKI_CHOICE, onEdit));
act(() => result.current.load({ discipline: 'cross_country', technique: 'classic' }));
expect(result.current.choice).toEqual({ discipline: 'cross_country', technique: 'classic' });
expect(onEdit).not.toHaveBeenCalled();
});
});
@@ -0,0 +1,26 @@
import { useCallback, useState } from 'react';
import type { SkiChoice } from './skiChoice';
/**
* SKI-02: a planned ski tour's discipline and cross-country technique, fields
* of the draft like a paddle tour's boat: nothing chosen until the traveller
* picks, and no step of the history. A technique stays remembered while
* another discipline is tried. `onEdit` tells the planner the draft changed,
* and says whether it may.
*/
export function useSkiFields(initial: SkiChoice, onEdit: () => boolean) {
const [choice, setChoice] = useState<SkiChoice>(initial);
const change = useCallback(
(next: SkiChoice) => {
if (next.discipline === choice.discipline && next.technique === choice.technique) return;
if (onEdit()) setChoice(next);
},
[choice, onEdit]
);
return {
choice,
change,
/** Loaded from a tour, a draft or an import, or cleared; not an edit. */
load: setChoice,
};
}