Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

chore(tours): keep the client ratchets where they were

Maurice9bc543a38714
diff --git a/client/src/components/Tours/planner/tourPlannerFacts.ts b/client/src/components/Tours/planner/tourPlannerFacts.ts
index c9ac9a6a2..2fdd8fcc7 100644
--- a/client/src/components/Tours/planner/tourPlannerFacts.ts
+++ b/client/src/components/Tours/planner/tourPlannerFacts.ts
@@ -167,6 +167,20 @@ function typeFieldsOf(input: TourPlannerFactsInput) {
};
}
+/** The types whose time is not the router's: a paddle tour has only its speed, a run its pace, a ride and a ski tour none. */
+const UNTIMED_BY_ROUTER: ReadonlySet<PlannableTourType> = new Set(['kayak', 'run', 'horse', 'ski']);
+
+/** The moving time a save carries: the planner's own, else the router's time standing in for a hike without heights. */
+function savedDurationSecondsOf(input: TourPlannerFactsInput, walkingDurationMinutes: number | null): number | null {
+ if (walkingDurationMinutes !== null) return walkingDurationMinutes * 60;
+ return UNTIMED_BY_ROUTER.has(input.tourType) ? null : input.durationSeconds;
+}
+
+/** SKI-02: a ski tour is saved with its discipline, a cross-country one with its technique too; null for any other type. */
+function skiMissingOf(input: TourPlannerFactsInput) {
+ return input.tourType === 'ski' ? skiChoiceMissing(input.ski ?? NO_SKI_CHOICE) : null;
+}
+
/**
* What the planner derives from its draft, worked out in one place: whether
* the fields hold, the times, and the fields the tour type adds to a save.
@@ -189,7 +203,7 @@ export function tourPlannerFacts(input: TourPlannerFactsInput) {
breakAdditionalInvalid: input.tourType !== 'walk' && invalidMinutes(breakAdditionalMinutes),
paddleIncomplete: isPaddle && (boatType === null || waterContext === null),
/** SKI-02: a ski tour is saved with its discipline, a cross-country one with its technique too. */
- skiMissing: input.tourType === 'ski' ? skiChoiceMissing(input.ski ?? NO_SKI_CHOICE) : null,
+ skiMissing: skiMissingOf(input),
/** RUN-01: a run is planned with a pace; without one Save waits, and a pace that is none is marked. */
runPaceMissing: isRun && input.runPaceSecondsPerKm === null,
runPaceInvalid: isRun && runPaceInvalid(input.runPaceSecondsPerKm),
@@ -204,14 +218,7 @@ export function tourPlannerFacts(input: TourPlannerFactsInput) {
automaticPlannedTotalMinutes > maxTourMinutesFor(input.stageCount ?? 1),
// A city walk's stops are its stays: it saves no breaks, so a cafe never counts as a stay and a break at once.
savedBreakAdditionalMinutes: input.tourType === 'walk' ? null : breakAdditionalMinutes,
- // The router's own time stands in for a hike without heights; a paddle tour has only its speed, a run its pace,
- // a ride and a ski tour none.
- savedDurationSeconds:
- walkingDurationMinutes === null
- ? isPaddle || isRun || input.tourType === 'horse' || input.tourType === 'ski'
- ? null
- : durationSeconds
- : walkingDurationMinutes * 60,
+ savedDurationSeconds: savedDurationSecondsOf(input, walkingDurationMinutes),
typeFields: typeFieldsOf(input),
};
}
diff --git a/client/src/components/Tours/planner/useTourRoute.ts b/client/src/components/Tours/planner/useTourRoute.ts
index ff95dab3c..46dffa835 100644
--- a/client/src/components/Tours/planner/useTourRoute.ts
+++ b/client/src/components/Tours/planner/useTourRoute.ts
@@ -202,6 +202,26 @@ function scheduleRoute(run: RouteRun): () => void {
return () => window.clearTimeout(timer);
}
+/**
+ * What a route was planned for: its points and the choices besides them, as a
+ * route of another type or profile is not this one's. A ski tour's choice
+ * counts as far as its routing lays the legs by it (nothing while they are
+ * drawn straight).
+ */
+function plannedKeyOf(waypointKey: string, inputs: TourRouteInputs): string {
+ const choices = [
+ inputs.tourType,
+ inputs.bikeProfile,
+ inputs.runProfile,
+ inputs.maxHikingDifficulty,
+ inputs.hikingPreferences,
+ inputs.paddleBoat,
+ inputs.paddleLakeStyle,
+ skiRouteKey(inputs.skiChoice),
+ ];
+ return `${waypointKey}#${JSON.stringify(choices)}`;
+}
+
/**
* The route of the planner's draft, planned again a moment after its points
* or its choices change: a hike on foot within its limit, a bike tour and a
@@ -248,20 +268,7 @@ export function useTourRoute(inputs: TourRouteInputs) {
const clearRoute = useCallback(() => setPlanned(NO_ROUTE), []);
const waypointKey = useMemo(() => tourWaypointKey(waypoints), [waypoints]);
- // What a route was planned for besides its points: a route of another type or profile is not this one's.
- // A ski tour's choice counts as far as its routing lays the legs by it (nothing while they are drawn straight).
- const skiKey = skiRouteKey(skiChoice);
- const choices = [
- tourType,
- bikeProfile,
- runProfile,
- maxHikingDifficulty,
- hikingPreferences,
- paddleBoat,
- paddleLakeStyle,
- skiKey,
- ];
- const plannedKey = `${waypointKey}#${JSON.stringify(choices)}`;
+ const plannedKey = plannedKeyOf(waypointKey, inputs);
// CW-02, CW-03: a station's own fields and the keys a save answered are no part of what a route is planned from,
// so a change to them alone plans nothing again.
const routeInputs = useMemo(() => routeInputsKey(waypoints), [waypoints]);
diff --git a/client/src/components/Tours/ski/skiDiscipline.ts b/client/src/components/Tours/ski/skiDiscipline.ts
index ba1e1a99b..2244b1ff2 100644
--- a/client/src/components/Tours/ski/skiDiscipline.ts
+++ b/client/src/components/Tours/ski/skiDiscipline.ts
@@ -20,7 +20,7 @@ const Snowboard = createLucideIcon('snowboard', [
* mean a city walk and a walk's moving time, so a snowshoe tile marked with
* them would read as a walk.
*/
-export const Snowshoe = createLucideIcon('snowshoe', [
+const Snowshoe = createLucideIcon('snowshoe', [
['path', { d: 'M12 3c3.3 0 5.5 2.8 5.5 6.5 0 4-2.4 7.6-5.5 12-3.1-4.4-5.5-8-5.5-12S8.7 3 12 3z', key: 'frame' }],
['path', { d: 'M7 7.5h10', key: 'lacing-front' }],
['path', { d: 'M7.3 13.5h9.4', key: 'lacing-back' }],
diff --git a/client/src/hooks/useRouteCalculation.ts b/client/src/hooks/useRouteCalculation.ts
index 6b89cae09..eef92c23d 100644
--- a/client/src/hooks/useRouteCalculation.ts
+++ b/client/src/hooks/useRouteCalculation.ts
@@ -5,8 +5,7 @@ import { useTripStore } from '../store/tripStore'
import { useSettingsStore } from '../store/settingsStore'
import { useAddonStore } from '../store/addonStore'
import { calculateRouteWithRetries, type RouteProfileKey } from '../components/Map/routeRetry'
-import { buildDayRouteRuns, hotelBookendOf, TRANSPORT_TYPES } from '../components/Map/dayRoutePlan'
-import type { TourStageStops } from '../components/Map/dayTourProjection'
+import { buildDayRouteRuns, hotelBookendOf, TRANSPORT_TYPES, type DayRouteInputs } from '../components/Map/dayRoutePlan'
import { dayViaLookup, foldViaLegs, threadVias, viaKeyOf, viasOnDayLeg } from '../utils/dayRouteVias'
import { resolveLegMode } from '../components/Planner/legMode'
import type { RoadtripVia } from '@trek/shared'
@@ -24,7 +23,7 @@ const NO_VIAS: Record<number, RoadtripVia[]> = {}
* `roadtripVias` are the road trip's vias by day: a road picked there is the road this
* day drives too (#2580). Absent, or empty while the road trip addon is off.
*/
-export function useRouteCalculation(tripStore: Pick<TripStoreState, 'assignments'> & { roadtripVias?: Record<number, RoadtripVia[]>; tourStageStops?: TourStageStops }, selectedDayId: number | null, enabled: boolean = true, profile: RouteProfileKey = 'driving', accommodations: Accommodation[] = NO_ACCOMMODATIONS) {
+export function useRouteCalculation(tripStore: Pick<TripStoreState, 'assignments'> & { roadtripVias?: Record<number, RoadtripVia[]>; tourStageStops?: DayRouteInputs['tourStageStops'] }, selectedDayId: number | null, enabled: boolean = true, profile: RouteProfileKey = 'driving', accommodations: Accommodation[] = NO_ACCOMMODATIONS) {
const viasByDay = tripStore.roadtripVias ?? NO_VIAS
// MDT-02: a day holding one stage of a multi-day tour routes to that stage.
const tourStageStops = tripStore.tourStageStops