fix(roadtrip): the drive between two days can take another way too

The drive from where one day ended to where the next begins was the one stretch of a
connected road trip that offered no other ways. The band above a card's first stop had no
button on the desk, and the phone did not show that drive at all. A via behind a day's last
stop, where the map already files a point dropped on that drive, was deleted when the day
was reordered under Days, and was left on no stop when that last stop was removed or
dragged up the day. Switching the avoided road classes or the day's profile kept the old
road and minutes on it until a reload.

The drive in now opens the same picker as any leg, on the desk band and on a new row at
the head of the phone's chain that names where it leaves. A choice is proven with the
seam's own router and written behind the last stop of the day before, also when a day with
a single stop lies between. The rule for that via lives once in shared (carriedSeam): it
stays with the last stop while that stop stays last, and is read like any other once it is
not, for the planner's drags and removals as for the server's sorts and seated nights. The
cached answer for a seam now records its mode and avoided classes, so changing either asks
for it again.
This commit is contained in:
Maurice
2026-09-23 09:42:22 +02:00
parent 53a422d22d
commit e6daed9403
51 changed files with 901 additions and 125 deletions
@@ -329,10 +329,16 @@ function legText(seg: RouteSegment | undefined, { t, unit }: RowChrome): string
* reads as a button that was pressed and stuck. Offline it keeps its place but dims,
* because a choice is saved as a via and vias are online only. Without `onAlternatives`
* (no permission, or a leg that cannot be rerouted) the column stays empty.
*
* With `origin` it is the drive in from where the day before ended, at the head of the
* card. The stop it leaves is not on this card, so its name goes above the pill; without
* it the chain would open on a drive from nowhere.
*/
export function RtLegRow({ seg, mode, chrome, onAlternatives, alternativesOpen = false, alternativesDisabled = false }: {
export function RtLegRow({ seg, mode, origin, chrome, onAlternatives, alternativesOpen = false, alternativesDisabled = false }: {
seg: RouteSegment | undefined
mode: string | null
/** The place the drive leaves from, named when it is not the stop drawn above it. */
origin?: string
chrome: RowChrome
/** Asks for other ways of driving this leg. Absent means the leg offers none. */
onAlternatives?: () => void
@@ -343,6 +349,12 @@ export function RtLegRow({ seg, mode, chrome, onAlternatives, alternativesOpen =
const { t } = chrome
const Icon = mode && LEG_ICONS[mode] ? LEG_ICONS[mode] : mode?.startsWith('plugin:') ? Zap : CarFront
const text = legText(seg, chrome)
const pill = (
<span className="my-1.5 flex min-w-0 items-center gap-[7px] rounded-[13px] bg-[color:var(--m-ic)] px-[11px] py-[7px]">
<Icon size={14} strokeWidth={2} className="flex-none text-m-muted" aria-hidden="true" />
<span className="truncate text-[0.75rem] font-semibold tabular-nums text-m-ink">{text}</span>
</span>
)
return (
<div className="grid items-center gap-x-[10px]" style={{ gridTemplateColumns: '34px 1fr auto' }}>
{/* flex-col, not flex: in a row the dashes would stretch sideways and read as
@@ -351,10 +363,14 @@ export function RtLegRow({ seg, mode, chrome, onAlternatives, alternativesOpen =
<span className="flex min-h-[40px] flex-col items-center" aria-hidden="true">
<span className="w-[2px] flex-1" style={{ backgroundImage: 'repeating-linear-gradient(var(--m-conn) 0 4px, transparent 4px 8px)' }} />
</span>
<span className="my-1.5 flex min-w-0 items-center gap-[7px] rounded-[13px] bg-[color:var(--m-ic)] px-[11px] py-[7px]">
<Icon size={14} strokeWidth={2} className="flex-none text-m-muted" aria-hidden="true" />
<span className="truncate text-[0.75rem] font-semibold tabular-nums text-m-ink">{text}</span>
</span>
{origin ? (
<span className="min-w-0">
<span className="mt-1.5 block truncate font-geist text-[0.65625rem] font-semibold text-m-muted">
{t('roadtrip.leg.arrivingFrom', { name: origin })}
</span>
{pill}
</span>
) : pill}
{onAlternatives ? (
<button
type="button"
@@ -16,7 +16,8 @@ import { formatDistance } from '../../../../utils/units'
import { formatClockTime } from '../../../../utils/formatters'
import { isRtlLanguage } from '../../../../i18n'
import type { MTripTabPanelProps } from '../MTripShell'
import { legReroutable, type StopRow } from '../../../../components/Roadtrip/roadtripRowModel'
import { arrivingReroutable, legReroutable, type StopRow } from '../../../../components/Roadtrip/roadtripRowModel'
import { ARRIVING_DRIVE, type RailDrive } from '../../../../components/Roadtrip/useRouteAlternatives'
import { dayBookings } from '../../../../components/Roadtrip/stopBookings'
import { getDayOrder } from '../../../../utils/dayOrder'
import type { Reservation } from '../../../../types'
@@ -276,18 +277,22 @@ export default function MRoadtripTab({ planner, shell }: MTripTabPanelProps) {
</Fragment>
)
}
if (row.kind === 'leg') {
// Only where the desk rail offers it too (legReroutable), and with the
// card's day id, the one the desk passes: the planner finds the day each
// stop is stored on by itself.
if (row.kind === 'leg' || row.kind === 'arriving') {
// Only where the desk rail offers it too (legReroutable, arrivingReroutable),
// and with the card's day id, the one the desk passes: the planner finds the
// day each stop is stored on by itself.
const leg = row.kind === 'leg'
const drive: RailDrive = leg ? { kind: 'leg', index: row.index } : ARRIVING_DRIVE
const reroutable = leg ? legReroutable(stage, row.index) : arrivingReroutable(stage)
return (
<RtLegRow
key={`l${i}`}
seg={row.seg}
mode={row.mode}
origin={leg ? undefined : row.from.name}
chrome={chrome}
onAlternatives={alts.canAsk && legReroutable(stage, row.index) ? () => alts.ask(stage.dayId, row.index) : undefined}
alternativesOpen={alts.isOpenFor(stage.dayId, row.index)}
onAlternatives={alts.canAsk && reroutable ? () => alts.ask(stage.dayId, drive) : undefined}
alternativesOpen={alts.isOpenFor(stage.dayId, drive)}
alternativesDisabled={!alts.editable}
/>
)
@@ -1,6 +1,6 @@
import { useEffect, useTransition } from 'react'
import { alternativesBusy, alternativesPhase, type AlternativeOverlay, type AlternativesPhase } from '../../../../components/Roadtrip/alternativeOverlays'
import type { LegAlternatives } from '../../../../components/Roadtrip/useRouteAlternatives'
import { openOn, type LegAlternatives, type RailDrive } from '../../../../components/Roadtrip/useRouteAlternatives'
import type { MTripShellApi, TripPlanner } from '../MTripShell'
/**
@@ -39,8 +39,9 @@ export interface MRtAlternativesController {
canConfirm: boolean
/** True while the chosen road is being checked against the router and written. */
saving: boolean
isOpenFor: (dayId: number, legIndex: number) => boolean
ask: (dayId: number, legIndex: number) => void
/** True while the picker is open on this drive of this card: a leg, or the drive in. */
isOpenFor: (dayId: number, drive: RailDrive) => boolean
ask: (dayId: number, drive: RailDrive) => void
pick: (index: number) => void
confirm: () => void
cancel: () => void
@@ -80,7 +81,7 @@ export function useMRtAlternatives(planner: TripPlanner, shell: MTripShellApi):
// picker, which the close button already does without pretending to save.
const canConfirm = !!picked && phase === 'choose' && !open?.routes[picked.index]?.current && editable && !saving
const isOpenFor = (dayId: number, legIndex: number) => open?.dayId === dayId && open.index === legIndex
const isOpenFor = (dayId: number, drive: RailDrive) => openOn(open, dayId, drive)
// The day chips, a swipe and the all days switch all move the stage under an open
// picker. `close` is the planner's stable callback, so this runs when the leg or the
@@ -90,11 +91,11 @@ export function useMRtAlternatives(planner: TripPlanner, shell: MTripShellApi):
if (open && open.dayId !== selectedDayId) close()
}, [open, selectedDayId, close])
const ask = (dayId: number, legIndex: number) => {
const ask = (dayId: number, drive: RailDrive) => {
// The planner's own ask toggles a leg that is already open, which is the desk
// button's second click. Here the pressed button on the chain is the way back to the
// answer on the map, so it must not close what it is pointing at.
if (!isOpenFor(dayId, legIndex)) {
if (!isOpenFor(dayId, drive)) {
// A pick belongs to the leg it was made on. Carried over, it would light a road
// on the next leg by its position in a list that leg never offered.
planner.setHighlightedAlternative(null)
@@ -103,7 +104,7 @@ export function useMRtAlternatives(planner: TripPlanner, shell: MTripShellApi):
planner.refuel.close()
// The card's day, as the desk passes it: the planner looks the stops up on that
// card and works out the day each one is stored on by itself.
planner.askRouteAlternatives(dayId, { kind: 'leg', index: legIndex })
planner.askRouteAlternatives(dayId, drive)
}
if (shell.rtView === 'list') shell.toggleRtView()
}