mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
fix(day-plan): make the legs from a booking or the hotel tappable on the phone
On the phone timeline only a leg that leaves a stop opened the travel mode menu. The leg from the morning hotel to the first stop, the leg from the last stop back to the hotel and the leg from a booking's arrival to the next stop stayed inert, although the desktop day plan already changes them through the stop at their other end. A TestFlight tester could not tap the walk from their train's arrival to the hotel. The timeline now knows which stop owns each of these legs: the first stop's incoming mode for the morning hotel leg and for a leg out of a booking, the last stop's outgoing mode for the evening hotel leg. Tapping them in edit mode opens the same menu as on the desktop, and the phone sets the incoming mode the way the desktop does. A leg no stop owns, such as a booking's arrival to the hotel, has no mode to store. It follows the day default, and on both the phone and the desktop it now offers the public transit search where a trip has dates, instead of reacting to nothing.
This commit is contained in:
@@ -585,3 +585,87 @@ describe('DayPlanSidebar, public transit between two city walks (CW-08)', () =>
|
||||
expect(screen.getByTestId('tour-day-overrun')).toHaveTextContent('Ends at 14:00, after Harbour starts at 13:00');
|
||||
});
|
||||
});
|
||||
|
||||
// The walk from a train's arrival to the night's hotel: no stop is at either end, so
|
||||
// there is no mode to change, and the desktop left it inert. The transit search is
|
||||
// what can be planned for it, as for every other leg.
|
||||
describe('DayPlanSidebar, public transit from a booking arrival to the hotel', () => {
|
||||
it('FE-PLANNER-DAYPLAN-171f: the walk from a train arrival to the hotel, which no stop owns, offers public transport', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onPlanTransitLeg = vi.fn();
|
||||
const days = [
|
||||
buildDay({ id: 10, date: '2025-06-01', title: 'Day 1' }),
|
||||
buildDay({ id: 11, date: '2025-06-02', title: 'Day 2' }),
|
||||
buildDay({ id: 12, date: '2025-06-03', title: 'Day 3' }),
|
||||
];
|
||||
const accommodations = [
|
||||
{
|
||||
id: 1,
|
||||
trip_id: 1,
|
||||
start_day_id: 10,
|
||||
end_day_id: 12,
|
||||
place_lat: 47.5,
|
||||
place_lng: 19.05,
|
||||
place_name: 'Basilica apARTment',
|
||||
},
|
||||
];
|
||||
const train = buildReservation({
|
||||
id: 430,
|
||||
type: 'train',
|
||||
title: 'Wien => Budapest',
|
||||
day_id: 11,
|
||||
end_day_id: 11,
|
||||
day_plan_position: 5,
|
||||
reservation_time: '2025-06-02T16:42:00',
|
||||
reservation_end_time: '2025-06-02T19:29:00',
|
||||
endpoints: [
|
||||
{
|
||||
role: 'from',
|
||||
sequence: 0,
|
||||
name: 'Wien Hbf',
|
||||
code: null,
|
||||
lat: 48.18,
|
||||
lng: 16.37,
|
||||
timezone: null,
|
||||
local_date: null,
|
||||
local_time: null,
|
||||
},
|
||||
{
|
||||
role: 'to',
|
||||
sequence: 1,
|
||||
name: 'Budapest Keleti',
|
||||
code: null,
|
||||
lat: 47.5,
|
||||
lng: 19.08,
|
||||
timezone: null,
|
||||
local_date: null,
|
||||
local_time: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
const albertina = buildPlace({ id: 1, name: 'Albertina', place_time: '12:00', lat: 48.2, lng: 16.37 });
|
||||
render(
|
||||
<DayPlanSidebar
|
||||
{...makeDefaultProps({
|
||||
days,
|
||||
assignments: { '11': [buildAssignment({ id: 11, day_id: 11, order_index: 0, place: albertina })] },
|
||||
accommodations,
|
||||
reservations: [train],
|
||||
selectedDayId: 11,
|
||||
routeShown: true,
|
||||
onPlanTransitLeg,
|
||||
})}
|
||||
/>
|
||||
);
|
||||
await user.click(await screen.findByLabelText('Public transit'));
|
||||
expect(contextMenu().queryByRole('button', { name: 'Driving' })).not.toBeInTheDocument();
|
||||
await user.click(contextMenu().getByRole('button', { name: 'Public transit' }));
|
||||
expect(onPlanTransitLeg).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
dayId: 11,
|
||||
from: expect.objectContaining({ lat: 47.5, lng: 19.08 }),
|
||||
to: { name: 'Basilica apARTment', lat: 47.5, lng: 19.05 },
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -69,7 +69,7 @@ import { findTodayDayId } from './today'
|
||||
import { markdownLinkComponents } from '../shared/markdownLink'
|
||||
import { RouteConnector, HotelRouteConnector } from './DayPlanSidebarRouteConnector'
|
||||
import { resolveLegMode } from './legMode'
|
||||
import { useLegModeActions } from './useLegModeActions'
|
||||
import { transitOnlyMenuItems, useLegModeActions } from './useLegModeActions'
|
||||
import { dayExportStops, fillAroundLocked } from './dayRoute'
|
||||
import { projectDayItinerary, projectedById, type TourStageStops } from '../Map/dayTourProjection'
|
||||
import type { DayRoutePoint } from '../Map/dayRoutePlan'
|
||||
@@ -1413,6 +1413,27 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP
|
||||
} as unknown as React.MouseEvent)
|
||||
}
|
||||
|
||||
// A hotel bookend leg opens the mode menu of the stop that owns it, the first stop's
|
||||
// incoming mode at the top and the last stop's outgoing mode at the bottom. One no
|
||||
// stop owns, a booking's arrival to the hotel, can only have transit planned.
|
||||
const hotelLegRow = (dayId: number, leg: { seg: RouteSegment; name: string; targetId?: number }, placement: 'top' | 'bottom') => {
|
||||
const connector = <HotelRouteConnector seg={leg.seg} name={leg.name} profile={routeProfile} placement={placement} />
|
||||
const targetId = leg.targetId
|
||||
const planTransit = targetId == null ? transitLegPlanner(dayId, leg.seg) : undefined
|
||||
const open = targetId != null
|
||||
? (e: React.MouseEvent) => (placement === 'top' ? openIncomingLegModeMenu : openLegModeMenu)(e, targetId, dayId, leg.seg)
|
||||
: planTransit && ((e: React.MouseEvent) => ctxMenu.open(e, transitOnlyMenuItems(planTransit, t)))
|
||||
if (!canEditDays || !open) return connector
|
||||
const label = targetId != null ? t('dayplan.transportMode.change') : t('transit.title')
|
||||
return (
|
||||
<Tooltip label={label} placement="top">
|
||||
<div role="button" tabIndex={0} onClick={open} onKeyDown={e => openLegMenuByKey(e, open)} style={{ cursor: 'pointer' }} aria-label={label}>
|
||||
{connector}
|
||||
</div>
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
// Sized as a flex child as well as by height: the desktop panel puts the Days / Road
|
||||
// trip switch above this, and at height 100% alone the list ran the switch's height
|
||||
@@ -1734,17 +1755,7 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP
|
||||
dropAfterLastItem(day.id, { assignmentId, noteId })
|
||||
}}
|
||||
>
|
||||
{hotelLegs[day.id]?.top && (() => {
|
||||
const targetId = hotelLegs[day.id]?.top?.targetId
|
||||
const connector = <HotelRouteConnector seg={hotelLegs[day.id]!.top!.seg} name={hotelLegs[day.id]!.top!.name} profile={routeProfile} placement="top" />
|
||||
return canEditDays && targetId != null ? (
|
||||
<Tooltip label={t('dayplan.transportMode.change')} placement="top">
|
||||
<div role="button" tabIndex={0} onClick={e => openIncomingLegModeMenu(e, targetId, day.id, hotelLegs[day.id]!.top!.seg)} onKeyDown={e => openLegMenuByKey(e, m => openIncomingLegModeMenu(m, targetId, day.id, hotelLegs[day.id]!.top!.seg))} style={{ cursor: 'pointer' }} aria-label={t('dayplan.transportMode.change')}>
|
||||
{connector}
|
||||
</div>
|
||||
</Tooltip>
|
||||
) : connector
|
||||
})()}
|
||||
{hotelLegs[day.id]?.top && hotelLegRow(day.id, hotelLegs[day.id]!.top!, 'top')}
|
||||
{daySchedule.byPosition[day.id]?.start.map(si => <PluginDayScheduleRow key={`${si.pluginId}:${si.id}`} item={si} />)}
|
||||
{visibleCount === 0 && !dayNoteUi ? (
|
||||
<div
|
||||
@@ -2477,17 +2488,7 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP
|
||||
})
|
||||
)}
|
||||
{daySchedule.byPosition[day.id]?.end.map(si => <PluginDayScheduleRow key={`${si.pluginId}:${si.id}`} item={si} />)}
|
||||
{hotelLegs[day.id]?.bottom && (() => {
|
||||
const targetId = hotelLegs[day.id]?.bottom?.targetId
|
||||
const connector = <HotelRouteConnector seg={hotelLegs[day.id]!.bottom!.seg} name={hotelLegs[day.id]!.bottom!.name} profile={routeProfile} placement="bottom" />
|
||||
return canEditDays && targetId != null ? (
|
||||
<Tooltip label={t('dayplan.transportMode.change')} placement="top">
|
||||
<div role="button" tabIndex={0} onClick={e => openLegModeMenu(e, targetId, day.id, hotelLegs[day.id]!.bottom!.seg)} onKeyDown={e => openLegMenuByKey(e, m => openLegModeMenu(m, targetId, day.id, hotelLegs[day.id]!.bottom!.seg))} style={{ cursor: 'pointer' }} aria-label={t('dayplan.transportMode.change')}>
|
||||
{connector}
|
||||
</div>
|
||||
</Tooltip>
|
||||
) : connector
|
||||
})()}
|
||||
{hotelLegs[day.id]?.bottom && hotelLegRow(day.id, hotelLegs[day.id]!.bottom!, 'bottom')}
|
||||
<AssistantDayPreview tripId={tripId} dayId={day.id} />{/* The assistant's waiting changes, then the drop zone at the list end */}
|
||||
<div
|
||||
style={{ minHeight: 12, padding: '2px 8px' }}
|
||||
|
||||
@@ -34,6 +34,15 @@ export function legModeMenuItems(
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The menu of a leg no stop owns, a booking's arrival to the night's hotel: nothing
|
||||
* keeps a mode for it, so it follows the day default and only public transit can be
|
||||
* planned for it.
|
||||
*/
|
||||
export function transitOnlyMenuItems(planTransit: () => void, t: Translate): LegModeMenuItem[] {
|
||||
return [{ label: t('transit.title'), icon: TramFront, onClick: planTransit }];
|
||||
}
|
||||
|
||||
export interface LegModeDeps {
|
||||
tripId: number;
|
||||
toast: { error: (message: string) => void };
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { LucideIcon } from 'lucide-react'
|
||||
import { useContextMenu, ContextMenu } from '../../../../components/shared/ContextMenu'
|
||||
import MarkdownText from '../../../../components/shared/MarkdownText'
|
||||
import { fmtTransitDuration } from '../../../../components/Planner/transitDisplay'
|
||||
import { legModeMenuItems } from '../../../../components/Planner/useLegModeActions'
|
||||
import { legModeMenuItems, transitOnlyMenuItems } from '../../../../components/Planner/useLegModeActions'
|
||||
import { formatTime } from '../../../../utils/formatters'
|
||||
import { useMPlanTimeline, type MPlanTimelineController } from './useMPlanTimeline'
|
||||
import { cityPillsForDay } from './planTimelineModel'
|
||||
@@ -114,16 +114,24 @@ function PlanDayPage({ planner, shell, dayId: pageDayId, active, editing, legMen
|
||||
const { t, trip, can } = planner
|
||||
const canEdit = can('day_edit', trip)
|
||||
const canEditPlaces = can('place_edit', trip)
|
||||
const openLegMenu = (e: MouseEvent, assignmentId: number, seg: RouteSegment) => {
|
||||
// Public transit sits under the road profiles, as on the desktop (#2398).
|
||||
// The tap on a leg while editing: the mode menu of the stop that owns it, its
|
||||
// outgoing mode for a leg it leaves, its incoming mode for one it enters from a
|
||||
// booking or the morning hotel, as on the desktop. Public transit sits under the
|
||||
// road profiles (#2398). A leg no stop owns, a booking's arrival to the hotel, can
|
||||
// only have transit planned, and stays inert where that is not available.
|
||||
const legTap = (seg: RouteSegment, owner: { id: number; incoming: boolean } | null): ((e: MouseEvent) => void) | undefined => {
|
||||
if (!editing) return undefined
|
||||
const transitLeg = tl.transitLegFor(seg)
|
||||
legMenu.open(e, legModeMenuItems(
|
||||
tl.routeModeOptions,
|
||||
mode => tl.setLegMode(assignmentId, mode),
|
||||
t,
|
||||
transitLeg ? () => tl.planTransitLeg(transitLeg, assignmentId) : undefined,
|
||||
))
|
||||
const planTransit = transitLeg
|
||||
? () => tl.planTransitLeg(transitLeg, owner && !owner.incoming ? owner.id : undefined)
|
||||
: undefined
|
||||
if (owner) {
|
||||
const pick = (mode: string | null) => (owner.incoming ? tl.setIncomingLegMode(owner.id, mode) : tl.setLegMode(owner.id, mode))
|
||||
return e => legMenu.open(e, legModeMenuItems(tl.routeModeOptions, pick, t, planTransit))
|
||||
}
|
||||
return planTransit ? e => legMenu.open(e, transitOnlyMenuItems(planTransit, t)) : undefined
|
||||
}
|
||||
const owned = (id: number | undefined, incoming: boolean) => (id != null ? { id, incoming } : null)
|
||||
const day = tl.day
|
||||
const dayId = day?.id
|
||||
// A stay chip shows the stay before anything can be changed, as on the
|
||||
@@ -249,7 +257,12 @@ function PlanDayPage({ planner, shell, dayId: pageDayId, active, editing, legMen
|
||||
)}
|
||||
|
||||
{tl.hotelLegs.top && (
|
||||
<HotelConnRow seg={tl.hotelLegs.top.seg} name={tl.hotelLegs.top.name} placement="top" />
|
||||
<HotelConnRow
|
||||
seg={tl.hotelLegs.top.seg}
|
||||
name={tl.hotelLegs.top.name}
|
||||
placement="top"
|
||||
onTap={legTap(tl.hotelLegs.top.seg, owned(tl.hotelLegs.top.assignmentId, true))}
|
||||
/>
|
||||
)}
|
||||
{dayId != null && daySchedule.byPosition[dayId]?.start.map(si => <PlanScheduleRow key={`${si.pluginId}:${si.id}`} item={si} />)}
|
||||
|
||||
@@ -321,13 +334,24 @@ function PlanDayPage({ planner, shell, dayId: pageDayId, active, editing, legMen
|
||||
/>
|
||||
)
|
||||
case 'conn':
|
||||
return <ConnRow key={row.key} seg={row.seg} onTap={editing && row.assignmentId != null ? e => openLegMenu(e, row.assignmentId!, row.seg) : undefined} />
|
||||
return (
|
||||
<ConnRow
|
||||
key={row.key}
|
||||
seg={row.seg}
|
||||
onTap={legTap(row.seg, row.assignmentId != null ? owned(row.assignmentId, false) : owned(row.incomingAssignmentId, true))}
|
||||
/>
|
||||
)
|
||||
}
|
||||
})}
|
||||
|
||||
{dayId != null && daySchedule.byPosition[dayId]?.end.map(si => <PlanScheduleRow key={`${si.pluginId}:${si.id}`} item={si} />)}
|
||||
{tl.hotelLegs.bottom && (
|
||||
<HotelConnRow seg={tl.hotelLegs.bottom.seg} name={tl.hotelLegs.bottom.name} placement="bottom" />
|
||||
<HotelConnRow
|
||||
seg={tl.hotelLegs.bottom.seg}
|
||||
name={tl.hotelLegs.bottom.name}
|
||||
placement="bottom"
|
||||
onTap={legTap(tl.hotelLegs.bottom.seg, owned(tl.hotelLegs.bottom.assignmentId, false))}
|
||||
/>
|
||||
)}
|
||||
|
||||
{tl.rows.length === 0 && !editing && (
|
||||
|
||||
@@ -534,18 +534,19 @@ export function PlanScheduleRow({ item }: { item: PluginDayScheduleItem }) {
|
||||
|
||||
// ── b4b) Accommodation bookend leg (hotel → first stop / last stop → hotel) ──
|
||||
|
||||
export function HotelConnRow({ seg, name, placement }: {
|
||||
export function HotelConnRow({ seg, name, placement, onTap }: {
|
||||
seg: RouteSegment
|
||||
name: string
|
||||
placement: 'top' | 'bottom'
|
||||
onTap?: (e: MouseEvent) => void
|
||||
}) {
|
||||
// Same line as the connectors between two stops, so a bookend leg routed with a
|
||||
// plugin profile or set to walking reads the same as the rest of the day (#1281).
|
||||
const travel = (
|
||||
<div className="flex items-center gap-2 py-px text-[color:var(--m-conn)]">
|
||||
<TravelLine seg={seg} />
|
||||
</div>
|
||||
)
|
||||
// plugin profile or set to walking reads the same as the rest of the day (#1281),
|
||||
// and taps the same way. Only the line is the button, the stay's name stays text.
|
||||
const cls = 'flex w-full items-center gap-2 py-px text-[color:var(--m-conn)]'
|
||||
const travel = onTap
|
||||
? <button type="button" onClick={onTap} className={`${cls} transition-transform active:scale-[.98]`}><TravelLine seg={seg} /></button>
|
||||
: <div className={cls}><TravelLine seg={seg} /></div>
|
||||
const hotel = (
|
||||
<div className="flex items-center justify-center gap-[5px] whitespace-nowrap font-geist text-[0.59375rem] font-semibold text-m-muted">
|
||||
<BedDouble size={11} strokeWidth={2} className="flex-none" />
|
||||
|
||||
@@ -31,7 +31,12 @@ export type PlanRow =
|
||||
| { key: string; kind: 'transport'; item: MergedItem; res: TransportEntry }
|
||||
| { key: string; kind: 'transit'; item: MergedItem; res: TransportEntry; transit: TransitMeta }
|
||||
| { key: string; kind: 'note'; item: MergedItem; note: DayNote }
|
||||
| { key: string; kind: 'conn'; seg: RouteSegment; assignmentId?: number }
|
||||
/**
|
||||
* A leg between two rows. `assignmentId` is the stop it leaves, whose outgoing mode it
|
||||
* uses; a leg that leaves a booking uses the incoming mode of the stop it enters,
|
||||
* `incomingAssignmentId`, as on the desktop day plan.
|
||||
*/
|
||||
| { key: string; kind: 'conn'; seg: RouteSegment; assignmentId?: number; incomingAssignmentId?: number }
|
||||
|
||||
export function parseReservationMeta(res: Reservation): Record<string, unknown> {
|
||||
let meta: unknown = res.metadata
|
||||
@@ -56,6 +61,26 @@ export function transportSubtitle(res: TransportEntry, t: TranslationFn): string
|
||||
const sameCoord = (a: [number, number], b: [number, number]): boolean =>
|
||||
Math.abs(a[0] - b[0]) < 1e-9 && Math.abs(a[1] - b[1]) < 1e-9
|
||||
|
||||
/**
|
||||
* The stops whose mode the two hotel bookend legs use: the first waypoint of the
|
||||
* day for the leg from the hotel (its incoming mode), the last for the leg back
|
||||
* (its outgoing mode). Absent where that end of the day is a booking, which no
|
||||
* stop owns.
|
||||
*/
|
||||
export interface BookendOwners {
|
||||
top?: number
|
||||
bottom?: number
|
||||
}
|
||||
|
||||
type PlanRowsOptions = {
|
||||
merged: MergedItem[]
|
||||
reservations: Reservation[]
|
||||
routeSegments: RouteSegment[]
|
||||
dayId: number
|
||||
toursEnabled?: boolean
|
||||
places?: Place[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the day's merged items to render rows and slot a travel-time connector
|
||||
* under the row each drawn leg belongs to. Segments are matched by their exact
|
||||
@@ -64,14 +89,12 @@ const sameCoord = (a: [number, number], b: [number, number]): boolean =>
|
||||
* front: they belong to the day's edges, and a stop planned on the hotel's own
|
||||
* spot would otherwise pair with them (#2501).
|
||||
*/
|
||||
export function buildPlanRows(opts: {
|
||||
merged: MergedItem[]
|
||||
reservations: Reservation[]
|
||||
routeSegments: RouteSegment[]
|
||||
dayId: number
|
||||
toursEnabled?: boolean
|
||||
places?: Place[]
|
||||
}): PlanRow[] {
|
||||
export function buildPlanRows(opts: PlanRowsOptions): PlanRow[] {
|
||||
return buildPlanTimeline(opts).rows
|
||||
}
|
||||
|
||||
/** buildPlanRows, plus the stops that own the day's two hotel bookend legs. */
|
||||
export function buildPlanTimeline(opts: PlanRowsOptions): { rows: PlanRow[]; bookendOwners: BookendOwners } {
|
||||
const { merged, reservations, routeSegments, dayId } = opts
|
||||
const pool = routeSegments.filter(s => !s.hotelBookend)
|
||||
const projected = new Map(projectDayItinerary(
|
||||
@@ -133,15 +156,24 @@ export function buildPlanRows(opts: {
|
||||
// A booking whose station is the stop itself leaves a leg that goes nowhere: the
|
||||
// transit planner saves a journey between two of the day's places at their own
|
||||
// coordinates. That is no walk and no drive, so it gets no connector.
|
||||
//
|
||||
// A leg out of a booking has no stop to keep its mode, so it uses the incoming mode
|
||||
// of the stop it enters, `toAssignmentId`, the one the route calc routed it in.
|
||||
type Origin = { at: [number, number]; row: number; assignmentId?: number }
|
||||
const legs = new Map<number, { seg: RouteSegment; assignmentId?: number }>()
|
||||
const connect = (origin: Origin | null, to: [number, number], toBooking = false) => {
|
||||
const legs = new Map<number, { seg: RouteSegment; assignmentId?: number; incomingAssignmentId?: number }>()
|
||||
const connect = (origin: Origin | null, to: [number, number], toBooking = false, toAssignmentId?: number) => {
|
||||
if (!origin) return
|
||||
const seg = takeSegment(origin.at, to)
|
||||
const fromBooking = origin.assignmentId == null
|
||||
if (!seg || ((toBooking || fromBooking) && sameCoord(origin.at, to))) return
|
||||
legs.set(origin.row, { seg, assignmentId: origin.assignmentId })
|
||||
legs.set(origin.row, {
|
||||
seg,
|
||||
assignmentId: origin.assignmentId,
|
||||
...(fromBooking && toAssignmentId != null ? { incomingAssignmentId: toAssignmentId } : {}),
|
||||
})
|
||||
}
|
||||
// The day's first waypoint, a stop or a booking's departure: the hotel leg runs into it.
|
||||
let first: { assignmentId?: number } | null = null
|
||||
let prev: Origin | null = null
|
||||
for (let i = 0; i < base.length; i++) {
|
||||
const row = base[i]
|
||||
@@ -151,7 +183,10 @@ export function buildPlanRows(opts: {
|
||||
if (row.assignment.route_excluded) continue
|
||||
const itineraryItem = projected.get(row.assignment.id)
|
||||
if (itineraryItem?.kind === 'tour') {
|
||||
if (itineraryItem.start) connect(prev, [itineraryItem.start.lat, itineraryItem.start.lng])
|
||||
if (itineraryItem.start) {
|
||||
first ??= { assignmentId: row.assignment.id }
|
||||
connect(prev, [itineraryItem.start.lat, itineraryItem.start.lng], false, row.assignment.id)
|
||||
}
|
||||
prev = itineraryItem.end
|
||||
? { at: [itineraryItem.end.lat, itineraryItem.end.lng], row: i, assignmentId: row.assignment.id }
|
||||
: null
|
||||
@@ -159,7 +194,8 @@ export function buildPlanRows(opts: {
|
||||
}
|
||||
if (place?.lat == null || place?.lng == null) continue
|
||||
const at: [number, number] = [place.lat, place.lng]
|
||||
connect(prev, at)
|
||||
first ??= { assignmentId: row.assignment.id }
|
||||
connect(prev, at, false, row.assignment.id)
|
||||
// The leg's mode is stored on its ORIGIN place assignment (#1281), so carry
|
||||
// that id for the tap-to-change menu.
|
||||
prev = { at, row: i, assignmentId: row.assignment.id }
|
||||
@@ -171,16 +207,23 @@ export function buildPlanRows(opts: {
|
||||
if (prev) prev = { ...prev, row: i }
|
||||
continue
|
||||
}
|
||||
if (from) first ??= {}
|
||||
// Only out of a stop: two bookings back to back are no drive (#1394).
|
||||
if (from && prev?.assignmentId != null) connect(prev, [from.lat, from.lng], true)
|
||||
prev = to ? { at: [to.lat, to.lng], row: i } : null
|
||||
}
|
||||
}
|
||||
|
||||
return base.flatMap((row, i): PlanRow[] => {
|
||||
const rows = base.flatMap((row, i): PlanRow[] => {
|
||||
const leg = legs.get(i)
|
||||
return leg ? [row, { key: `conn-${row.key}`, kind: 'conn', seg: leg.seg, assignmentId: leg.assignmentId }] : [row]
|
||||
return leg ? [row, { key: `conn-${row.key}`, kind: 'conn', ...leg }] : [row]
|
||||
})
|
||||
// The last waypoint is where the day ends: a stop, or a booking's arrival (no owner).
|
||||
const bookendOwners: BookendOwners = {
|
||||
...(first?.assignmentId != null ? { top: first.assignmentId } : {}),
|
||||
...(prev?.assignmentId != null ? { bottom: prev.assignmentId } : {}),
|
||||
}
|
||||
return { rows, bookendOwners }
|
||||
}
|
||||
|
||||
export interface HotelChip {
|
||||
@@ -218,7 +261,12 @@ export function hotelChipsForDay(day: Day, days: Day[], accommodations: Accommod
|
||||
return chips.filter(c => c.name).sort((a, b) => rank[a.variant] - rank[b.variant])
|
||||
}
|
||||
|
||||
export interface HotelLeg { seg: RouteSegment; name: string }
|
||||
export interface HotelLeg {
|
||||
seg: RouteSegment
|
||||
name: string
|
||||
/** The stop whose mode the leg uses (see BookendOwners); absent when a booking ends it. */
|
||||
assignmentId?: number
|
||||
}
|
||||
export interface HotelLegs { top: HotelLeg | null; bottom: HotelLeg | null }
|
||||
|
||||
/**
|
||||
@@ -242,17 +290,19 @@ export function hotelLegsForDay(
|
||||
days: Day[],
|
||||
accommodations: Accommodation[],
|
||||
routeSegments: RouteSegment[],
|
||||
owners: BookendOwners = {},
|
||||
): HotelLegs {
|
||||
const { morning, evening } = getDayBookendHotels(day, days, accommodations)
|
||||
const legOf = (a: Accommodation | undefined, bookend: 'morning' | 'evening'): HotelLeg | null => {
|
||||
const legOf = (a: Accommodation | undefined, bookend: 'morning' | 'evening', owner?: number): HotelLeg | null => {
|
||||
if (!a || a.place_lat == null || a.place_lng == null) return null
|
||||
const at: [number, number] = [a.place_lat, a.place_lng]
|
||||
const seg = routeSegments.find(s => s.hotelBookend === bookend && sameCoord(bookend === 'morning' ? s.from : s.to, at))
|
||||
return seg ? { seg, name: accommodationName(a) } : null
|
||||
if (!seg) return null
|
||||
return { seg, name: accommodationName(a), ...(owner != null ? { assignmentId: owner } : {}) }
|
||||
}
|
||||
// A moving day without stops is one drive from one hotel to the next (#1297). The
|
||||
// calc tags it as the morning leg, so it shows once, at the top (#2476).
|
||||
return { top: legOf(morning, 'morning'), bottom: legOf(evening, 'evening') }
|
||||
return { top: legOf(morning, 'morning', owners.top), bottom: legOf(evening, 'evening', owners.bottom) }
|
||||
}
|
||||
|
||||
/** The day headline as city pills — a "Tokyo → Kyoto" title becomes two pills with an arrow. */
|
||||
|
||||
@@ -14,8 +14,8 @@ import type { PlannedTransitLeg, TransitLeg } from '../../../../components/Plann
|
||||
import { useTransitLegPlanner } from '../../../../components/Planner/useTransitLegPlanner'
|
||||
import { dayItemOverrun } from '../../../../components/Tours/tourDayTime'
|
||||
import {
|
||||
buildPlanRows, breaksChronology, findUpNext, hotelChipsForDay, hotelLegsForDay, itemHasTime,
|
||||
type HotelLegs, type PlanRow, type TransportEntry,
|
||||
buildPlanTimeline, breaksChronology, findUpNext, hotelChipsForDay, hotelLegsForDay, itemHasTime,
|
||||
type BookendOwners, type HotelLegs, type PlanRow, type TransportEntry,
|
||||
} from './planTimelineModel'
|
||||
import type { TripPlanner } from '../MTripShell'
|
||||
import type { WeatherResult } from '@trek/shared'
|
||||
@@ -99,16 +99,17 @@ export function useMPlanTimeline(planner: TripPlanner, forDayId?: number | null)
|
||||
tripAccommodations,
|
||||
)
|
||||
|
||||
const rows = useMemo<PlanRow[]>(() => {
|
||||
if (!day) return []
|
||||
return buildPlanRows({ merged, reservations, routeSegments: connSegments, dayId: day.id, toursEnabled: planner.toursEnabled, places: planner.places })
|
||||
const timeline = useMemo<{ rows: PlanRow[]; bookendOwners: BookendOwners }>(() => {
|
||||
if (!day) return { rows: [], bookendOwners: {} }
|
||||
return buildPlanTimeline({ merged, reservations, routeSegments: connSegments, dayId: day.id, toursEnabled: planner.toursEnabled, places: planner.places })
|
||||
}, [day, merged, reservations, connSegments, planner.toursEnabled, planner.places])
|
||||
const rows = timeline.rows
|
||||
|
||||
// Accommodation bookend legs (hotel → first stop, last stop → hotel). The
|
||||
// segments already sit in connSegments; hotelLegsForDay picks the two out.
|
||||
const hotelLegs = useMemo<HotelLegs>(
|
||||
() => (day ? hotelLegsForDay(day, days, tripAccommodations, connSegments) : { top: null, bottom: null }),
|
||||
[day, days, tripAccommodations, connSegments],
|
||||
() => (day ? hotelLegsForDay(day, days, tripAccommodations, connSegments, timeline.bookendOwners) : { top: null, bottom: null }),
|
||||
[day, days, tripAccommodations, connSegments, timeline.bookendOwners],
|
||||
)
|
||||
|
||||
const hotelChips = useMemo(
|
||||
@@ -375,6 +376,17 @@ export function useMPlanTimeline(planner: TripPlanner, forDayId?: number | null)
|
||||
persistLegMode(assignmentId, mode)
|
||||
}, [day, persistLegMode])
|
||||
|
||||
// The same for the leg entering a stop: from a booking's arrival or from the
|
||||
// morning hotel, which no stop leaves (as on the desktop day plan).
|
||||
const setIncomingLegMode = useCallback((assignmentId: number, mode: string | null) => {
|
||||
if (!day) return
|
||||
const key = String(day.id)
|
||||
useTripStore.setState(state => ({
|
||||
assignments: { ...state.assignments, [key]: (state.assignments[key] || []).map(a => (a.id === assignmentId ? { ...a, incoming_leg_transport_mode: mode } : a)) },
|
||||
}))
|
||||
persistLegMode(assignmentId, mode, 'incoming')
|
||||
}, [day, persistLegMode])
|
||||
|
||||
// ── Public transit for one leg (#2398) ──
|
||||
// The entry the desktop connector menu carries: the automated search, seeded with
|
||||
// the leg's two ends and the time the stop it leaves is planned for, between two city
|
||||
@@ -394,8 +406,9 @@ export function useMPlanTimeline(planner: TripPlanner, forDayId?: number | null)
|
||||
toursEnabled: planner.toursEnabled, tourOf, onPlan: tripHasDates ? openTransitSearch : undefined,
|
||||
})
|
||||
const transitLegFor = useCallback((seg: RouteSegment): TransitLeg | null => (day ? legFor(day.id, seg) : null), [day, legFor])
|
||||
// `originId` is the stop the leg leaves, which tells two walks ending at one spot apart.
|
||||
const planTransitLeg = useCallback((leg: TransitLeg, originId: number) => {
|
||||
// `originId` is the stop the leg leaves, which tells two walks ending at one spot apart;
|
||||
// a leg that leaves a booking or the hotel has none.
|
||||
const planTransitLeg = useCallback((leg: TransitLeg, originId?: number) => {
|
||||
if (day) plan(day.id, leg, originId)
|
||||
}, [day, plan])
|
||||
// A saved journey that now arrives after the walk it leads to starts (CW-08).
|
||||
@@ -414,7 +427,7 @@ export function useMPlanTimeline(planner: TripPlanner, forDayId?: number | null)
|
||||
moveRowTo,
|
||||
addPlace, addBooking, addTransport,
|
||||
optimize, canExportRoute, routeTargets, exportGoogleMaps, exportCoMaps, renameDay, fullPlaceOf,
|
||||
routeModeOptions, setLegMode, transitLegFor, planTransitLeg, journeyLate, tourOverrun,
|
||||
routeModeOptions, setLegMode, setIncomingLegMode, transitLegFor, planTransitLeg, journeyLate, tourOverrun,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user