mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
feat(roadtrip): a booked night can stand at both ends of its days
The drive learns what a booked night at the edge of a day is, while nothing seats one yet. One rule in shared, seatNightBookends, picks the stay a day wakes up in and the one it sleeps in the way Days does, over real nights and in id order, and puts each hotel at the edge of the day as a stop of its own that belongs to no assignment. The schedule, the day window, the spill into the next morning, the sums and the connected days read a night spent at one hotel as a leg going nowhere, never cut or postpone the drive to tonight's hotel, and pass the hotel over wherever a stop is looked up by its stored index. That lookup now also puts a place added behind a terminal where it fell. The rail and the phone chain draw the hotel as a row of its own that opens the booking or the stay, offers no other ways and takes no via, in every language. Until a trip switches it on, every plan is the one stored.
This commit is contained in:
@@ -4,18 +4,19 @@ import MDancingTrek from '../../../components/MDancingTrek'
|
||||
import MIconBtn from '../../../components/MIconBtn'
|
||||
import { formatDurationShort, serviceColor } from '../../../../components/Roadtrip/roadtripModel'
|
||||
import { bookingOpens, carrierIcon, rideText, terminalLine } from '../../../../components/Roadtrip/carrierRide'
|
||||
import { BOOKEND_ICON, bookendMeta, bookendTitle } from '../../../../components/Roadtrip/nightBookend'
|
||||
import { bookingClock, bookingIcon } from '../../../../components/Roadtrip/stopBookings'
|
||||
import { STOP_KIND_BY_KEY } from '../../../../components/Roadtrip/stopKinds'
|
||||
import { formatDistance } from '../../../../utils/units'
|
||||
import { formatClockTime } from '../../../../utils/formatters'
|
||||
import type { RoadtripRow, StopRow } from '../../../../components/Roadtrip/roadtripRowModel'
|
||||
import type { BookendReading, RoadtripRow, StopRow } from '../../../../components/Roadtrip/roadtripRowModel'
|
||||
import type { RefuelSearch } from '../../../../components/Roadtrip/useRefuelSearch'
|
||||
import { REFUEL_EMPTY_KEY, REFUEL_WORDS, refuelBandState, type RefuelCandidate } from '../../../../components/Roadtrip/refuelSuggestion'
|
||||
import type { DistanceUnit, RouteSegment, ScheduleWarning } from '@trek/shared/roadtrip'
|
||||
import type { Reservation, TranslationFn } from '../../../../types'
|
||||
|
||||
/**
|
||||
* The four row types of the mobile drive chain, plus the two bands that interrupt it.
|
||||
* The row types of the mobile drive chain, plus the two bands that interrupt it.
|
||||
*
|
||||
* What the desktop rail does in five stacked 8px badges per stop, this does in at most
|
||||
* two 10.5px marks: on touch there is no hover, so a badge nobody can explain is worse
|
||||
@@ -127,10 +128,25 @@ function warningMark(warning: ScheduleWarning, chrome: RowChrome): ReactNode {
|
||||
}
|
||||
|
||||
/**
|
||||
* A stop of the stage. The whole row is the tap target, at least 46px tall, which is
|
||||
* why it is a div with role rather than a button: the desktop needs controls nested
|
||||
* inside its row, and a button inside a button is not markup.
|
||||
* A row of the stage that is its own tap target, at least 46px tall, which is why it is a
|
||||
* div with role rather than a button: the desktop needs controls nested inside its row,
|
||||
* and a button inside a button is not markup.
|
||||
*/
|
||||
function TapRow({ onOpen, children }: { onOpen: () => void; children: ReactNode }) {
|
||||
return (
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={onOpen}
|
||||
onKeyDown={e => { if (e.target === e.currentTarget && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); onOpen() } }}
|
||||
className="grid cursor-pointer items-center gap-x-[10px] py-1" style={{ gridTemplateColumns: '34px 1fr auto' }}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** A stop of the stage; see `TapRow`. */
|
||||
export function RtStopRow({ row, chrome, onOpen, onPickKind }: {
|
||||
row: StopRow
|
||||
chrome: RowChrome
|
||||
@@ -157,13 +173,7 @@ export function RtStopRow({ row, chrome, onOpen, onPickKind }: {
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={onOpen}
|
||||
onKeyDown={e => { if (e.target === e.currentTarget && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); onOpen() } }}
|
||||
className="grid cursor-pointer items-center gap-x-[10px] py-1" style={{ gridTemplateColumns: '34px 1fr auto' }}
|
||||
>
|
||||
<TapRow onOpen={onOpen}>
|
||||
<span className="flex justify-center"><Disc row={row} t={t} onPickKind={onPickKind} /></span>
|
||||
<span className="min-w-0 py-2">
|
||||
<span className={`block text-[0.875rem] leading-[1.25] ${row.service ? 'truncate font-medium text-m-muted' : 'line-clamp-2 font-semibold text-m-ink'}`}>
|
||||
@@ -178,7 +188,47 @@ export function RtStopRow({ row, chrome, onOpen, onPickKind }: {
|
||||
{formatClockTime(row.time, chrome.is12h)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</TapRow>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A booked night at the edge of the stage: the hotel the day sets out from, or the one it
|
||||
* ends at. Laid out like a stop, on the bed a stay wears, with no number and no kind to
|
||||
* pick: it is the stay's place, not a stop of the day. Under it the latest hour the room
|
||||
* is handed back, on the morning it is, and the one finding a row has room for. The whole
|
||||
* row opens the booking behind the night, or the stay.
|
||||
*/
|
||||
export function RtBookendRow({ row, bookend, chrome, onOpen }: {
|
||||
row: StopRow
|
||||
bookend: BookendReading
|
||||
chrome: RowChrome
|
||||
onOpen: () => void
|
||||
}) {
|
||||
const { t } = chrome
|
||||
const meta = bookendMeta(bookend, t, chrome.is12h)
|
||||
return (
|
||||
<TapRow onOpen={onOpen}>
|
||||
<span className="flex justify-center">
|
||||
<span className="grid h-[30px] w-[30px] shrink-0 place-items-center rounded-full bg-[color:var(--m-ic)] text-m-ink">
|
||||
<BOOKEND_ICON size={15} strokeWidth={2.1} aria-hidden="true" />
|
||||
</span>
|
||||
</span>
|
||||
<span className="min-w-0 py-2">
|
||||
<span className="line-clamp-2 block text-[0.875rem] font-semibold leading-[1.25] text-m-ink">{bookendTitle(bookend, t)}</span>
|
||||
{(meta || row.warning) && (
|
||||
<span className="mt-[4px] flex flex-wrap items-center gap-[5px]">
|
||||
{meta && <span className="font-geist text-[0.65625rem] font-medium text-m-muted">{meta}</span>}
|
||||
{row.warning && warningMark(row.warning, chrome)}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
{row.time && (
|
||||
<span dir="ltr" className="whitespace-nowrap text-[0.8125rem] font-medium tabular-nums text-m-faint">
|
||||
{formatClockTime(row.time, chrome.is12h)}
|
||||
</span>
|
||||
)}
|
||||
</TapRow>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useMRtCorridor } from './useMRtCorridor'
|
||||
import { useMRtAlternatives } from './useMRtAlternatives'
|
||||
import MRtCorridorBar from './MRtCorridorBar'
|
||||
import MRtAlternativesBar from './MRtAlternativesBar'
|
||||
import { RtAutoRow, RtBookingChips, RtDryRow, RtLegRow, RtRideRow, RtSpillRow, RtStopRow, type RowChrome } from './MRoadtripRows'
|
||||
import { RtAutoRow, RtBookendRow, RtBookingChips, RtDryRow, RtLegRow, RtRideRow, RtSpillRow, RtStopRow, type RowChrome } from './MRoadtripRows'
|
||||
import MBadge from '../../../components/MBadge'
|
||||
import MDancingTrek from '../../../components/MDancingTrek'
|
||||
import { formatDurationShort } from '../../../../components/Roadtrip/roadtripModel'
|
||||
@@ -19,6 +19,7 @@ import type { MTripTabPanelProps } from '../MTripShell'
|
||||
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 { bookendBooking } from '../../../../components/Roadtrip/nightBookend'
|
||||
import { getDayOrder } from '../../../../utils/dayOrder'
|
||||
import { undatedRides } from '@trek/shared/roadtrip'
|
||||
import type { Reservation, TranslationFn } from '../../../../types'
|
||||
@@ -84,6 +85,7 @@ export default function MRoadtripTab({ planner, shell }: MTripTabPanelProps) {
|
||||
const openStop = (row: StopRow) => {
|
||||
// A terminal is the booking's, and opens it: there is no stop sheet for an airport.
|
||||
if (row.stop.carrier) shell.openSheet('transport', { reservationId: row.stop.carrier.reservationId })
|
||||
else if (row.bookend) openBookend(row.stop.ownerDayId, row.bookend)
|
||||
else shell.openSheet('rtstop', { dayId: row.stop.ownerDayId, assignmentId: row.stop.assignmentId })
|
||||
}
|
||||
|
||||
@@ -116,6 +118,16 @@ export default function MRoadtripTab({ planner, shell }: MTripTabPanelProps) {
|
||||
planner.setEditingReservation(res)
|
||||
planner.setShowReservationModal(true)
|
||||
}
|
||||
// A booked night at the edge of the stage is no stop, and has no stop sheet: it opens the
|
||||
// booking behind the night, else the stay for somebody who may edit days, else the
|
||||
// hotel's place, the way a stay chip in the day timeline does (#2210).
|
||||
const openBookend = (dayId: number, reading: NonNullable<StopRow['bookend']>) => {
|
||||
const booking = bookendBooking(reading, canEditBookings)
|
||||
const res = booking === null ? undefined : planner.reservations.find(r => r.id === booking)
|
||||
if (res) openBooking(res)
|
||||
else if (planner.can('day_edit', planner.trip)) shell.openSheet('accommodation', { dayId, accId: reading.accommodationId })
|
||||
else planner.handlePlaceClick(reading.placeId)
|
||||
}
|
||||
|
||||
// The search bar sits in the same band on both halves, at the same offset, so the
|
||||
// list/map switch never moves it: it is one stage seen two ways, and a control that
|
||||
@@ -261,6 +273,9 @@ export default function MRoadtripTab({ planner, shell }: MTripTabPanelProps) {
|
||||
|
||||
<section className="mt-2.5 overflow-hidden rounded-[22px] border border-[color:var(--m-cbr)] bg-[color:var(--m-card)] px-3.5 pb-3 pt-1">
|
||||
{rt.rows.map((row, i) => {
|
||||
if (row.kind === 'stop' && row.bookend) {
|
||||
return <RtBookendRow key={`s${i}`} row={row} bookend={row.bookend} chrome={chrome} onOpen={() => openStop(row)} />
|
||||
}
|
||||
if (row.kind === 'stop') {
|
||||
const chips = bookings.atStop.get(row.stop.assignmentId)
|
||||
return (
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useTranslation } from '../../../../i18n'
|
||||
import { useSettingsStore } from '../../../../store/settingsStore'
|
||||
import { formatClock, formatDurationShort, parseClock } from '../../../../components/Roadtrip/roadtripModel'
|
||||
import { stageOf } from '../../../../components/Roadtrip/roadtripRowModel'
|
||||
import { isStoredStop } from '@trek/shared/roadtrip'
|
||||
import { locateStop, missedLeaveOf } from '../../../../components/Roadtrip/stayReading'
|
||||
import { useLeaveMode, type LeaveMode } from '../../../../components/Roadtrip/useLeaveMode'
|
||||
import { formatClockTime } from '../../../../utils/formatters'
|
||||
@@ -110,7 +111,9 @@ export default function MRtStaySheet({ planner, shell }: MTripSheetsProps) {
|
||||
const arrival = useMemo(() => {
|
||||
if (located) return located.entry?.arrival ?? null
|
||||
if (!stage || stopPlaceId == null) return null
|
||||
const index = stage.stops.findIndex(s => s.placeId === stopPlaceId)
|
||||
// A stored stop at the place: the hotel a day sets out from shares the place of the
|
||||
// hotel's own stop and comes first on the card, with a clock of its own.
|
||||
const index = stage.stops.findIndex(s => isStoredStop(s) && s.placeId === stopPlaceId)
|
||||
if (index === -1) return null
|
||||
return stage.schedule.entries[index]?.arrival ?? null
|
||||
}, [located, stage, stopPlaceId])
|
||||
|
||||
Reference in New Issue
Block a user