mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
fix(mobile): offer public transit in the day plan's leg menu, as on the desktop
The connector menu on the phone listed only the road profiles, so the transit search could not be opened for a single leg there. It now carries the Public transit entry whenever the trip has dates, seeded with the leg's two ends and the departure of the stop it leaves, and the transport sheet passes that departure on to the search. The prefill is built by one module the desktop day plan now uses as well. Closes #2398
This commit is contained in:
@@ -2,7 +2,7 @@ import { useRef, useState, type MouseEvent } from 'react'
|
||||
import {
|
||||
ArrowRight, BedDouble, CalendarDays, CalendarRange, ChevronRight, Compass, LogIn, LogOut,
|
||||
MapPin, Pencil, PencilLine, Route, Ticket, TrainFront, Undo2,
|
||||
Car, Footprints, Zap, RotateCcw,
|
||||
Car, Footprints, Zap, RotateCcw, TramFront,
|
||||
} from 'lucide-react'
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import { useContextMenu, ContextMenu } from '../../../../components/shared/ContextMenu'
|
||||
@@ -22,6 +22,7 @@ import { Fragment } from 'react'
|
||||
import MDancingTrek from '../../../components/MDancingTrek'
|
||||
import type { MPlanTimelineProps } from '../MTripShell'
|
||||
import type { MergedItem } from '../../../../utils/dayMerge'
|
||||
import type { RouteSegment } from '../../../../types'
|
||||
import type { Assignment } from '../../../../types'
|
||||
import type { ComponentType, ReactNode } from 'react'
|
||||
import GoogleMapsIcon from '../../../../components/shared/GoogleMapsIcon'
|
||||
@@ -45,9 +46,12 @@ export default function MPlanTimeline({ planner, shell }: MPlanTimelineProps) {
|
||||
// Per-segment travel mode (#1281): tap a connector → pick the leg's mode.
|
||||
const legMenu = useContextMenu()
|
||||
const modeIcon = (key: string) => (key === 'walking' ? Footprints : key.startsWith('plugin:') ? Zap : Car)
|
||||
const openLegMenu = (e: MouseEvent, assignmentId: number) => {
|
||||
const openLegMenu = (e: MouseEvent, assignmentId: number, seg: RouteSegment) => {
|
||||
// Public transit sits under the road profiles, as on the desktop (#2398).
|
||||
const transitLeg = tl.transitLegFor(seg)
|
||||
legMenu.open(e, [
|
||||
...tl.routeModeOptions.map(o => ({ label: o.label, icon: modeIcon(o.key), onClick: () => tl.setLegMode(assignmentId, o.key) })),
|
||||
...(transitLeg ? [{ label: t('transit.title'), icon: TramFront, onClick: () => tl.planTransitLeg(transitLeg) }] : []),
|
||||
{ divider: true },
|
||||
{ label: t('dayplan.transportMode.useDefault'), icon: RotateCcw, onClick: () => tl.setLegMode(assignmentId, null) },
|
||||
])
|
||||
@@ -250,7 +254,7 @@ export default function MPlanTimeline({ planner, shell }: MPlanTimelineProps) {
|
||||
/>
|
||||
)
|
||||
case 'conn':
|
||||
return <ConnRow key={row.key} seg={row.seg} onTap={editing && row.assignmentId != null ? e => openLegMenu(e, row.assignmentId!) : undefined} />
|
||||
return <ConnRow key={row.key} seg={row.seg} onTap={editing && row.assignmentId != null ? e => openLegMenu(e, row.assignmentId!, row.seg) : undefined} />
|
||||
}
|
||||
})}
|
||||
|
||||
|
||||
@@ -6,13 +6,14 @@ import { usePluginStore } from '../../../../store/pluginStore'
|
||||
import { getDayBookendHotels } from '../../../../utils/dayOrder'
|
||||
import { getDisplayTimeForDay, getMergedItems, getTransportForDay, hasCarrierEndpointOnDay } from '../../../../utils/dayMerge'
|
||||
import { dayCoMapsUrl, dayGoogleMapsUrl, optimizeDayOrder } from '../lib/dayRoute'
|
||||
import { buildTransitLeg, buildTransitNameIndex, type TransitLeg } from '../../../../components/Planner/transitLeg'
|
||||
import {
|
||||
buildPlanRows, breaksChronology, findUpNext, hotelChipsForDay, hotelLegsForDay, itemHasTime,
|
||||
type HotelLegs, type PlanRow, type TransportEntry,
|
||||
} from './planTimelineModel'
|
||||
import type { TripPlanner } from '../MTripShell'
|
||||
import type { WeatherResult } from '@trek/shared'
|
||||
import type { Assignment, Place } from '../../../../types'
|
||||
import type { Assignment, Place, RouteSegment } from '../../../../types'
|
||||
import type { MergedItem } from '../../../../utils/dayMerge'
|
||||
|
||||
/**
|
||||
@@ -376,6 +377,29 @@ export function useMPlanTimeline(planner: TripPlanner) {
|
||||
})
|
||||
}, [day, tripId, toast, t, tripActions])
|
||||
|
||||
// ── 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. It needs the
|
||||
// trip's dates, as on the desktop and as the day sheet's own transit button does.
|
||||
const tripHasDates = Boolean(planner.trip?.start_date && planner.trip?.end_date)
|
||||
const transitNames = useMemo(
|
||||
() => buildTransitNameIndex(assignments, tripAccommodations, reservations),
|
||||
[assignments, tripAccommodations, reservations],
|
||||
)
|
||||
const transitLegFor = useCallback((seg: RouteSegment): TransitLeg | null => {
|
||||
if (!day || !tripHasDates) return null
|
||||
return buildTransitLeg(seg, day.id, transitNames, assignments, reservations)
|
||||
}, [day, tripHasDates, transitNames, assignments, reservations])
|
||||
|
||||
const planTransitLeg = useCallback((leg: TransitLeg) => {
|
||||
if (!day) return
|
||||
planner.setTransportModalDayId(day.id)
|
||||
planner.setEditingTransport(null)
|
||||
planner.setTransitPrefill(leg)
|
||||
planner.setTransportModalAutomated(true)
|
||||
planner.setShowTransportModal(true)
|
||||
}, [planner, day])
|
||||
|
||||
return {
|
||||
day, rows, hotelLegs, merged, hotelChips, weather, weatherTemp, upNext,
|
||||
weatherPlaceName: weatherAnchor?.name ?? null,
|
||||
@@ -385,7 +409,7 @@ export function useMPlanTimeline(planner: TripPlanner) {
|
||||
moveRowTo,
|
||||
addPlace, addBooking, addTransport,
|
||||
optimize, exportGoogleMaps, exportCoMaps, renameDay, fullPlaceOf,
|
||||
routeModeOptions, setLegMode,
|
||||
routeModeOptions, setLegMode, transitLegFor, planTransitLeg,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -704,6 +704,7 @@ export default function MTransportFormSheet({ planner, onOpenExpense }: MTranspo
|
||||
onAdd={(p) => saveTransport(p as Record<string, unknown> & { title: string })}
|
||||
initialFrom={transitPrefill?.from ?? null}
|
||||
initialTo={transitPrefill?.to ?? null}
|
||||
initialTime={transitPrefill?.time ?? null}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user