mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
feat(roadtrip): leave a stop at its End and show the stay that makes
A visit's End could be edited and was shown in road trip mode, but the schedule never read it: the drive always left a stop after its stay, so a traveller who knew when they had to leave but not how long they would stand there had no way to say so. The End is now the time the drive leaves. RoadtripStop.leaveAt is filled from the visit's End (or its place's) on the client by useRoadtripRoutes and on the server by roadtrip-plan.service, so calculate_roadtrip and get_roadtrip_context agree with the planner, and computeSchedule takes it as the departure it already knew how to hold. With Start and End both set the stay is the time between them. With daily travel times on, the stay is the time until then, and an End before the window start starts the day early the way a Start does. Before the first fixed time the chain works backwards through an End as it does through a pinned Start. An End is read against the drive: the last passing of that clock time counts as missed when the drive went past it on the road or earlier the same day, anything else is the next one, so a drive across midnight neither waits a whole day nor pretends to be on time. A drive that gets there after the End leaves on arrival and files a missedLeave finding, shown beside the late badge in the rail and on the phone. The rail's STAY badge, the inspector's Stay tile, the phone stop sheet and the phone chain show the stay the End makes, with an "until 14:00" hint. It is read off the schedule and never written to duration_minutes: the stay belongs to the place, the End to one visit, and a stored copy would go stale as soon as the arrival moved. For such a stop the stay dialog, desktop and phone, shows that stay read only and offers to remove the End, through the visit's time route with an offline path (assignmentRepo.setTimes, setAssignmentTimes). While the road trip is on, the End field in both place forms says the drive leaves at that time. The dead checkoutAt in the plan service is gone. New strings in all 23 locales.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { ArrowRight, Minus, Plus } from 'lucide-react'
|
||||
import { AlertTriangle, ArrowRight, Minus, Plus } from 'lucide-react'
|
||||
import MSheet from '../../../components/MSheet'
|
||||
import MChip from '../../../components/MChip'
|
||||
import type { MTripSheetsProps } from '../MTripShell'
|
||||
@@ -7,9 +7,11 @@ import { useTranslation } from '../../../../i18n'
|
||||
import { useSettingsStore } from '../../../../store/settingsStore'
|
||||
import { formatClock, formatDurationShort, parseClock } from '../../../../components/Roadtrip/roadtripModel'
|
||||
import { stageOf } from '../../../../components/Roadtrip/roadtripRowModel'
|
||||
import { locateStop, missedLeaveOf } from '../../../../components/Roadtrip/stayReading'
|
||||
import { useLeaveMode, type LeaveMode } from '../../../../components/Roadtrip/useLeaveMode'
|
||||
import { formatClockTime } from '../../../../utils/formatters'
|
||||
import { FormSheetHeader } from '../sheets/PlSheetChrome'
|
||||
import { INNER_CLS } from '../sheets/MTripSheetUi'
|
||||
import { INNER_CLS, displayTime } from '../sheets/MTripSheetUi'
|
||||
|
||||
/** What the chain hands over when a stop's stay is tapped. */
|
||||
interface RtStaySheetPayload {
|
||||
@@ -102,12 +104,24 @@ export default function MRtStaySheet({ planner, shell }: MTripSheetsProps) {
|
||||
*/
|
||||
const stage = stageOf(planner.roadtripRoutes.days, planner.selectedDayId)
|
||||
const stopPlaceId = stop?.placeId
|
||||
// The visit itself when the stop sheet named it, read off the same stage: its end time
|
||||
// decides whether there is a stay to choose here at all.
|
||||
const located = stage && stop?.assignmentId != null ? locateStop([stage], stop.assignmentId) : null
|
||||
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)
|
||||
if (index === -1) return null
|
||||
return stage.schedule.entries[index]?.arrival ?? null
|
||||
}, [stage, stopPlaceId])
|
||||
}, [located, stage, stopPlaceId])
|
||||
const leave = useLeaveMode(located && {
|
||||
leaveAt: located.stop.leaveAt,
|
||||
arrival: located.entry?.arrival,
|
||||
departure: located.entry?.departure,
|
||||
missedBy: missedLeaveOf(located.day, located.index),
|
||||
assignmentId: located.stop.assignmentId,
|
||||
dayId: located.stop.ownerDayId,
|
||||
})
|
||||
|
||||
// What the stay does to this stop: the arrival is fixed by the drive, the departure is
|
||||
// the one end this sheet moves.
|
||||
@@ -170,9 +184,13 @@ export default function MRtStaySheet({ planner, shell }: MTripSheetsProps) {
|
||||
onClose={shell.closeSheet}
|
||||
variant="bottom"
|
||||
material="opaque"
|
||||
ariaLabel={t('roadtrip.stay.add')}
|
||||
// Named for what it holds: a stop left at a set time has no stay to add.
|
||||
ariaLabel={leave.until ? t('roadtrip.stop.stay') : t('roadtrip.stay.add')}
|
||||
>
|
||||
{stop && (
|
||||
{stop && leave.until && (
|
||||
<RtLeaveTime name={stop.name} leave={leave} arrival={arrival} departure={located?.entry?.departure ?? null} onClose={shell.closeSheet} />
|
||||
)}
|
||||
{stop && !leave.until && (
|
||||
<>
|
||||
<FormSheetHeader
|
||||
title={t('roadtrip.stay.add')}
|
||||
@@ -293,3 +311,74 @@ export default function MRtStaySheet({ planner, shell }: MTripSheetsProps) {
|
||||
</MSheet>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The sheet for a stop the traveller leaves at a set time, where there is no stay to pick.
|
||||
*
|
||||
* It says when the drive leaves and what stay that makes, and offers the one thing there
|
||||
* is to do: take the end time off the visit, after which the stay is a choice again.
|
||||
*/
|
||||
function RtLeaveTime({ name, leave, arrival, departure, onClose }: {
|
||||
name?: string
|
||||
leave: LeaveMode
|
||||
arrival: string | null
|
||||
departure: string | null
|
||||
onClose: () => void
|
||||
}) {
|
||||
const { t, locale } = useTranslation()
|
||||
const timeFormat = useSettingsStore(s => s.settings.time_format) || '24h'
|
||||
const until = displayTime(leave.until, locale, timeFormat)
|
||||
const captionCls = 'font-geist text-[0.5625rem] font-bold uppercase tracking-[.09em] text-m-faint'
|
||||
return (
|
||||
<>
|
||||
<FormSheetHeader title={t('roadtrip.stop.stay')} onClose={onClose} closeLabel={t('common.close')} />
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-[18px] pb-1">
|
||||
{name && <div className="truncate text-[0.875rem] font-semibold text-m-ink">{name}</div>}
|
||||
<div className="mt-[18px] text-center text-[2.5rem] font-extrabold leading-none tabular-nums text-m-ink">
|
||||
{leave.minutes === null ? t('roadtrip.stay.until', { time: until }) : formatDurationShort(leave.minutes * 60)}
|
||||
</div>
|
||||
{/* What the drive actually does, as the desktop dialog says it: reached too late it
|
||||
leaves on arrival, with the travel hours over first it goes on in the morning. */}
|
||||
{leave.missedBy !== null ? (
|
||||
<div className="mt-[10px] flex items-center justify-center gap-1.5 text-center text-[0.8125rem] font-medium leading-snug text-[color:var(--m-st-pending)]">
|
||||
<AlertTriangle size={14} strokeWidth={2} className="flex-none" aria-hidden="true" />
|
||||
{t('roadtrip.warn.missedLeave', { minutes: leave.missedBy })}
|
||||
</div>
|
||||
) : (
|
||||
<div className="mt-[10px] text-center text-[0.8125rem] leading-snug text-m-muted">
|
||||
{t(leave.dayEndsFirst ? 'roadtrip.stay.dayEndsFirst' : 'roadtrip.stay.leavesAt', { time: until })}
|
||||
</div>
|
||||
)}
|
||||
{arrival && !leave.dayEndsFirst && (
|
||||
<div className={`mt-[18px] flex items-center justify-center gap-4 rounded-[16px] px-3 py-[11px] ${INNER_CLS}`}>
|
||||
<span className="flex flex-col items-center gap-[2px]">
|
||||
<span className={captionCls}>{t('roadtrip.stay.arrive')}</span>
|
||||
<span dir="ltr" className="text-[0.875rem] font-bold tabular-nums text-m-muted">
|
||||
{displayTime(arrival, locale, timeFormat)}
|
||||
</span>
|
||||
</span>
|
||||
<ArrowRight size={14} strokeWidth={2} className="mt-[11px] flex-none text-m-faint" aria-hidden="true" />
|
||||
<span className="flex flex-col items-center gap-[2px]">
|
||||
<span className={captionCls}>{t('roadtrip.stay.leave')}</span>
|
||||
<span dir="ltr" className="text-[0.875rem] font-bold tabular-nums text-m-ink">
|
||||
{displayTime(departure ?? leave.until, locale, timeFormat)}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{leave.remove && (
|
||||
<div className="flex flex-none items-center gap-2 border-t border-[color:var(--m-rowbr)] px-[18px] pb-4 pt-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { void leave.remove?.() }}
|
||||
disabled={leave.removing}
|
||||
className="ml-auto inline-flex h-11 items-center rounded-full bg-m-act px-[18px] text-[0.8125rem] font-semibold text-m-actfg disabled:opacity-40"
|
||||
>
|
||||
{t('roadtrip.stay.clearLeave')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { useTripStore } from '../../../../store/tripStore'
|
||||
import ChargingInfo from '../../../../components/Roadtrip/ChargingInfo'
|
||||
import { formatDurationShort } from '../../../../components/Roadtrip/roadtripModel'
|
||||
import { roadtripRows, stageOf, type StopRow } from '../../../../components/Roadtrip/roadtripRowModel'
|
||||
import { readStay, shownStay } from '../../../../components/Roadtrip/stayReading'
|
||||
import { STOP_KIND_BY_KEY } from '../../../../components/Roadtrip/stopKinds'
|
||||
import { getNavigationTargets, openNavigationTarget } from '../../../../components/Planner/placeNavigation'
|
||||
import { NavigationMenu } from '../../../../components/shared/NavigationMenu'
|
||||
@@ -39,10 +40,11 @@ import type { RoadtripDay, ScheduleWarning } from '@trek/shared/roadtrip'
|
||||
*
|
||||
* Editing the place is the one way out of that rule, and it is a hand-over rather than a
|
||||
* control of this sheet: the pencil opens the place editor the plan tab opens, with this
|
||||
* very visit in context, and this sheet closes behind it. The time somebody fixed for a
|
||||
* stop is that editor's start time (the chain anchors on the visit's own start time), so
|
||||
* a time control here would be a second writer for one number. A booked night can also
|
||||
* be held by its check-in, which belongs to the booking and not to the place.
|
||||
* very visit in context, and this sheet closes behind it. The times somebody fixed for a
|
||||
* stop are that editor's Start and End (the chain arrives at the visit's own Start and
|
||||
* leaves at its End), so a time control here would be a second writer for one number. A
|
||||
* booked night can also be held by its check-in, which belongs to the booking and not to
|
||||
* the place.
|
||||
*/
|
||||
|
||||
interface RtStopSheetPayload {
|
||||
@@ -203,16 +205,17 @@ export default function MRtStopSheet({ planner, shell }: MTripSheetsProps) {
|
||||
// Every finding filed at this stop, not just the one the chain had room for: being late
|
||||
// and driving too far are separate answers and the sheet is where both fit.
|
||||
const warnings: ScheduleWarning[] = [
|
||||
...day.schedule.warnings.filter(w => w.index === index && w.code === 'late'),
|
||||
...day.schedule.warnings.filter(w => w.index === index && (w.code === 'late' || w.code === 'missedLeave')),
|
||||
...day.driveWarnings.filter(w => w.index === index && (w.code === 'leg' || w.code === 'range')),
|
||||
]
|
||||
const warningText = (w: ScheduleWarning): string => {
|
||||
if (w.code === 'late') return t('roadtrip.warn.late', { minutes: w.minutes ?? 0 })
|
||||
if (w.code === 'missedLeave') return t('roadtrip.warn.missedLeave', { minutes: w.minutes ?? 0 })
|
||||
if (w.code === 'range') return t('roadtrip.limit.range', { distance: formatDistance(w.sinceKm ?? 0, unit) })
|
||||
return t('roadtrip.limit.legOver', { time: formatDurationShort((w.overMinutes ?? 0) * 60) })
|
||||
}
|
||||
const warningIcon = (w: ScheduleWarning): ReactNode => {
|
||||
if (w.code === 'late') return <AlertTriangle size={15} strokeWidth={2} />
|
||||
if (w.code === 'late' || w.code === 'missedLeave') return <AlertTriangle size={15} strokeWidth={2} />
|
||||
if (w.code === 'range') return <Fuel size={15} strokeWidth={2} />
|
||||
return <Hourglass size={15} strokeWidth={2} />
|
||||
}
|
||||
@@ -226,7 +229,13 @@ export default function MRtStopSheet({ planner, shell }: MTripSheetsProps) {
|
||||
else if (navTargets.length > 1) setNavOpen(true)
|
||||
}
|
||||
|
||||
const stayMinutes = stop.dwellMinutes
|
||||
// A stop left at a set time is stood at until then: the stay is what that time leaves
|
||||
// of it, and the sheet says until when.
|
||||
const stay = readStay(stop, entry)
|
||||
const missed = warnings.some(w => w.code === 'missedLeave')
|
||||
const shown = shownStay(stay)
|
||||
const until = stay.until ? t('roadtrip.stay.until', { time: displayTime(stay.until, locale, timeFormat) }) : null
|
||||
const stayText = [shown === null ? null : formatDurationShort(shown * 60), until].filter(Boolean).join(' ')
|
||||
const canEditPlace = planner.can('place_edit', planner.trip)
|
||||
const editStay = () => {
|
||||
// The row this sheet is on rides along, because the stay sheet comes back here when it
|
||||
@@ -235,7 +244,7 @@ export default function MRtStopSheet({ planner, shell }: MTripSheetsProps) {
|
||||
// that is not on screen, which is what the day swipe reads to decide it is blocked.
|
||||
shell.openSheet('rtstay', {
|
||||
placeId: stop.placeId,
|
||||
minutes: stayMinutes,
|
||||
minutes: stop.dwellMinutes,
|
||||
name: stop.name,
|
||||
dayId: located.day.dayId,
|
||||
assignmentId: stop.assignmentId,
|
||||
@@ -353,17 +362,27 @@ export default function MRtStopSheet({ planner, shell }: MTripSheetsProps) {
|
||||
<div className="mt-2 font-geist text-[0.65625rem] leading-snug text-m-faint">
|
||||
{entry?.anchored ? t('roadtrip.stop.pinned') : t('roadtrip.stop.computed')}
|
||||
</div>
|
||||
{/* Only where it is true. Reached too late the stop is left on arrival, which
|
||||
the finding below says; with the travel hours over first the drive goes on
|
||||
in the morning, not at the time or at the Leave shown above. */}
|
||||
{stay.until && !missed && (
|
||||
<div className="mt-1 font-geist text-[0.65625rem] leading-snug text-m-faint">
|
||||
{t(stay.dayEndsFirst ? 'roadtrip.stay.dayEndsFirst' : 'roadtrip.stay.leavesAt', {
|
||||
time: displayTime(stay.until, locale, timeFormat),
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── What this stop costs, and what the drive to it went past ── */}
|
||||
{(!!stayMinutes || !!row.offRoadMeters || warnings.length > 0) && (
|
||||
{(!!stayText || !!row.offRoadMeters || warnings.length > 0) && (
|
||||
<div className="mt-2.5 flex flex-col gap-2">
|
||||
{!!stayMinutes && (
|
||||
{!!stayText && (
|
||||
<Finding
|
||||
icon={<Hourglass size={15} strokeWidth={2} />}
|
||||
label={t('roadtrip.stop.stayShort')}
|
||||
value={formatDurationShort(stayMinutes * 60)}
|
||||
value={stayText}
|
||||
/>
|
||||
)}
|
||||
{!!row.offRoadMeters && (
|
||||
@@ -399,7 +418,7 @@ export default function MRtStopSheet({ planner, shell }: MTripSheetsProps) {
|
||||
<ActionTile
|
||||
icon={<Clock size={16} strokeWidth={2} />}
|
||||
label={t('roadtrip.stop.stayShort')}
|
||||
value={stayMinutes ? formatDurationShort(stayMinutes * 60) : t('roadtrip.stay.none')}
|
||||
value={stayText || t('roadtrip.stay.none')}
|
||||
onClick={canEditPlace ? editStay : undefined}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -29,6 +29,9 @@ export default function PlTimeFields({
|
||||
planner, startTime, endTime, onChange, assignmentId, dayAssignments, hasTimeError,
|
||||
}: PlTimeFieldsProps) {
|
||||
const { t } = planner
|
||||
// Opened from the road trip tab, where the End of a visit is when the drive leaves it.
|
||||
// The plan tab reads the day as Days does, and there End stays a plain label.
|
||||
const endIsLeave = planner.activeTab === 'roadtrip'
|
||||
|
||||
const collisions = useMemo(() => {
|
||||
if (!startTime || startTime.length < 5) return []
|
||||
@@ -58,6 +61,9 @@ export default function PlTimeFields({
|
||||
<div className="min-w-0 flex-1">
|
||||
<Eyebrow className="mb-[5px] uppercase">{t('places.endTime')}</Eyebrow>
|
||||
<CustomTimePicker value={endTime} onChange={v => onChange('end_time', v)} />
|
||||
{endIsLeave && (
|
||||
<div className="mt-[5px] font-geist text-[0.65625rem] leading-snug text-m-faint">{t('roadtrip.stop.endIsLeave')}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{hasTimeError && (
|
||||
|
||||
Reference in New Issue
Block a user