fix(mobile): a road trip stage draws only its own rides, not the drive's flight home

The phone's road trip tab shows one stage at a time, but its map drew the
arcs of every ride that seams the whole drive, plus every booking switched on
for any day. A flight home on the 12th then crossed the map of the stage on
the 9th, with its airport label, as if it were part of that day.

The stage now draws the rides that seam its own drive, whatever day they were
booked on, and of the bookings switched on by hand only those that run on the
stage's day. The all-days view and the desktop, which shows the whole drive,
are unchanged.
This commit is contained in:
Maurice
2026-11-20 23:00:52 +01:00
parent 8ab7547edf
commit 6ebd5cf0c7
3 changed files with 56 additions and 5 deletions
@@ -1,9 +1,9 @@
import { describe, expect, it } from 'vitest'
import { dayColor } from './dayColors'
import { stageMapData, stagePlaceIds, stagePoints } from './stageMap'
import { stageConnectionIds, stageMapData, stagePlaceIds, stagePoints } from './stageMap'
import type { AccessSpur, RoadtripDay, RoadtripRoutes, RoadtripStop } from '@trek/shared/roadtrip'
// FE-RTSTAGE-001 to FE-RTSTAGE-021
// FE-RTSTAGE-001 to FE-RTSTAGE-023
function stop(name: string, over: Partial<RoadtripStop> = {}): RoadtripStop {
return {
@@ -268,3 +268,23 @@ describe('a stage that starts or ends at a booked night', () => {
expect(data.accessLines).toEqual([walk])
})
})
describe('stageConnectionIds', () => {
const flight = (reservationId: number, role: 'arrival' | 'departure') =>
stop('Airport', { carrier: { reservationId, type: 'flight', role, title: 'Flight', code: null, at: null } })
it("FE-RTSTAGE-022: a stage draws its own rides, not the drive's ride home from a later day", () => {
// The flight in (31) seams this stage; the flight home (32) belongs to a stage days later
// and is not on this one at all.
const stage = day([flight(31, 'arrival'), stop('Ubud')])
expect(stageConnectionIds(stage, [], () => true)).toEqual([31])
})
it('FE-RTSTAGE-023: of the bookings switched on by hand only those running on the stage day stay', () => {
const stage = day([stop('Ubud')])
const onThisDay = new Set([40])
expect(stageConnectionIds(stage, [40, 41], id => onThisDay.has(id))).toEqual([40])
// A ride that seams the stage stays even when it was booked on another day.
expect(stageConnectionIds(day([flight(31, 'arrival')]), [31], () => false)).toEqual([31])
})
})
@@ -1,4 +1,5 @@
import { dayColor } from './dayColors'
import { carrierReservationIds } from '@trek/shared/roadtrip'
import type { AccessSpur, RoadtripDay, RoadtripRoutes } from '@trek/shared/roadtrip'
/**
@@ -88,6 +89,20 @@ export function stagePlaceIds(stage: RoadtripDay): Set<number> {
return new Set(stage.stops.filter(s => !s.automaticNight).map(s => s.placeId))
}
/**
* The bookings the map draws as arcs on ONE stage: the rides that seam this stage's
* drive, whatever day they were booked on, and of the ones switched on by hand only
* those that run on the stage's day. Taking the rides of the whole drive put a flight
* home across every stage before it, as if it were part of that day.
*/
export function stageConnectionIds(
stage: RoadtripDay,
switchedOn: readonly number[],
runsOnStageDay: (reservationId: number) => boolean,
): number[] {
return [...new Set([...switchedOn.filter(runsOnStageDay), ...carrierReservationIds([stage])])]
}
/** The stage's stops as coordinates, for the fit. */
export function stagePoints(stage: RoadtripDay): [number, number][] {
return stage.stops
@@ -8,7 +8,7 @@ import PoiCategoryPill from '../../../../components/Map/PoiCategoryPill'
import { usePoiExplore } from '../../../../components/Map/usePoiExplore'
import { useMergedMapPois } from '../../../../components/Map/useMergedMapPois'
import { firstStopOfPlace, stageOf } from '../../../../components/Roadtrip/roadtripRowModel'
import { stageMapData } from '../../../../components/Roadtrip/stageMap'
import { stageConnectionIds, stageMapData } from '../../../../components/Roadtrip/stageMap'
import { usePlanMapViewport } from '../../../../hooks/usePlanMapViewport'
import { useIsDark } from '../../../../hooks/useIsDark'
import { useTileUrl } from '../../../../hooks/useTileUrl'
@@ -21,6 +21,7 @@ import { RT_ALT_BAR_LIFT } from '../roadtrip/useMRtAlternatives'
import type { MMapAreaProps } from '../MTripShell'
import type { Poi } from '../../../../components/Map/poiCategories'
import type { ViewportPadding } from '../../../../utils/mapViewport'
import { runsOnDay } from '../../../../utils/reservationRoutes'
/** One array, so an explore set switched off does not move every pin on the stage. */
const NO_POIS: Poi[] = []
@@ -215,6 +216,20 @@ export default function MMapArea({ planner, shell }: MMapAreaProps) {
() => onStage ? stageMapData(planner.roadtripRoutes, stage, !!dayColorsOn) : null,
[onStage, planner.roadtripRoutes, stage, dayColorsOn],
)
// The arcs the stage draws: its own rides and what was switched on for its day. The
// all-days view keeps every ride of the drive.
const stageConnections = useMemo(() => {
if (!onStage) return null
if (!stage) return planner.roadtripConnections
const byId = new Map(planner.reservations.map(r => [r.id, r]))
return stageConnectionIds(stage, planner.visibleConnections, id => {
const r = byId.get(id)
return !r || runsOnDay(r, planner.selectedDayId, planner.days)
})
}, [
onStage, stage, planner.roadtripConnections, planner.reservations,
planner.visibleConnections, planner.selectedDayId, planner.days,
])
// Only what the stage carries, so a trip's other 200 pins stay off a screen that
// is answering one question. Without a stage (the all-days view) every place a stored
@@ -412,10 +427,11 @@ export default function MMapArea({ planner, shell }: MMapAreaProps) {
// toggled on or not, the way the desktop map does it in road trip mode. The
// ride's leg carries no geometry, so without this the road ended at the
// departure terminal and picked up again at the arrival with nothing between.
visibleConnectionIds={onStage ? planner.roadtripConnections : planner.visibleConnections}
visibleConnectionIds={stageConnections ?? planner.visibleConnections}
// The plan map shows one day, so a booking switched on for another day stays off
// it until that day is picked, or the whole trip is. The switch itself is still
// trip-wide. The stage keeps its seamed rides whatever day they were booked on.
// trip-wide. The stage scopes its own set above, since its seamed rides stay on
// it whatever day they were booked on.
scopeConnectionsToDay={!onStage}
// Transport overlay tap → the mobile transport detail sheet (desktop
// routes this through mapTransportDetail into the day sidebar instead).