fix(roadtrip): match cross-day returns to their rental

Keep located waypoints when the return desk is missing and assign them unique IDs. Join separate days only for the same hire car in both the planner and server. Keep the existing public terminal roles.
This commit is contained in:
Maurice
2026-11-30 22:15:12 +01:00
parent 7de6bc39cd
commit d0cf936bf6
10 changed files with 207 additions and 81 deletions
@@ -122,7 +122,7 @@ function rideEnd(stop: RoadtripStop, entry: ScheduleEntry | undefined, t: Transl
placeLine: carrier.code && carrier.code !== place ? place : null,
clock,
dayOffset: entry?.dayOffset ?? 0,
label: clock ? t(key, { time: clock }) : null,
label: clock && carrier.role !== 'stop' ? t(key, { time: clock }) : null,
}
}
@@ -1,5 +1,5 @@
import { useRoadtripSettings } from '../../hooks/useRoadtripSettings'
import { assembleRoadtrip, bookendStaysOf, carrierLegsFor, carrierSeam, foldRouteRun, hotelBookendsOn, isCarrierMode, isStationaryJoin, mergeRouteSegments, oneNightPerStay, seatCarrierStops, seatNightBookends, standsAsDay, terminalAssignmentId, viasOnLeg, type CarrierSeam, type RoadtripStop, type RoadtripRoutes, type PlanDay, type QuietDay, type RoutedLeg } from '@trek/shared/roadtrip'
import { assembleRoadtrip, bookendStaysOf, carrierLegsFor, carrierSeam, foldRouteRun, hotelBookendsOn, incomingDayJoin, isCarrierMode, isStationaryJoin, mergeRouteSegments, oneNightPerStay, seatCarrierStops, seatNightBookends, standsAsDay, terminalAssignmentId, viasOnLeg, type CarrierSeam, type RoadtripStop, type RoadtripRoutes, type PlanDay, type QuietDay, type RoutedLeg } from '@trek/shared/roadtrip'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { avoidedClasses, calculateRouteWithLegs, routeEngineFor, RoutingRefusedError } from '../Map/RouteCalculator'
import { routerAsks } from '../Map/routerAsks'
@@ -693,26 +693,13 @@ export function useRoadtripRoutes(
want(from, to, chain.dayId)
}
}
// And, when the traveller asks for one continuous drive, the road from each card's
// last stop to the next card's first — the one gap a day-at-a-time routing leaves.
if (connectDays) {
for (let d = 0; d < routingChains.length - 1; d++) {
const from = routingChains[d].stops[routingChains[d].stops.length - 1]
const to = routingChains[d + 1].stops[0]
if (from && to) want(from, to, routingChains[d + 1].dayId)
}
} else {
// The drive back to a hire car's desk is the booking's own road, not the gap
// between two cards, so it is drawn whether or not one continuous drive was asked
// for. A car taken out in the morning and handed back after midnight had the day
// it set out on drawn and nothing from there to the desk, which reads as a drive
// that stops halfway.
for (let d = 1; d < routingChains.length; d++) {
const to = routingChains[d].stops[0]
if (to?.carrier?.role !== 'return') continue
const from = routingChains[d - 1].stops[routingChains[d - 1].stops.length - 1]
if (from) want(from, to, routingChains[d].dayId)
}
for (let d = 1; d < routingChains.length; d++) {
const previous = routingChains[d - 1]
const chain = routingChains[d]
if (!previous || !chain) continue
const to = chain.stops[0]
const from = incomingDayJoin(previous.stops, chain.stops, connectDays)
if (from && to) want(from, to, chain.dayId)
}
return { seams: out, seamMisses: misses }
}, [chains, plan, quietDays, window, legsByDay, seamLegs, rideLegs, viasByDay, connectDays, legModeOf, avoidKey, distanceUnit])