mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +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:
@@ -2,6 +2,7 @@ import { useCallback, useMemo, useRef, useState } from 'react'
|
||||
import { calculateRouteWithLegs } from '../Map/RouteCalculator'
|
||||
import { lineLengthKm, parseTrack, planTrack, trackGapKm, type FollowTrackPlan } from './followTrack'
|
||||
import type { LatLng } from './corridor'
|
||||
import { isStoredStop } from '@trek/shared/roadtrip'
|
||||
import type { RoadtripRoutes } from './useRoadtripRoutes'
|
||||
import type { RoadtripVias } from './useRoadtripVias'
|
||||
|
||||
@@ -99,13 +100,20 @@ export function useFollowTrack(
|
||||
const [outcome, setOutcome] = useState<FollowTrackOutcome | null>(null)
|
||||
const abort = useRef<AbortController | null>(null)
|
||||
|
||||
const day = useMemo(() => routes.days.find(d => d.dayId === dayId), [routes.days, dayId])
|
||||
const stops = useMemo<LatLng[]>(() => {
|
||||
const original = day?.automaticSchedule
|
||||
? routes.days.flatMap(d => d.stops).filter(s => !s.automaticNight && s.ownerDayId === dayId).sort((a, b) => a.ownerIndex - b.ownerIndex)
|
||||
: day?.stops ?? []
|
||||
return original.map(s => ({ lat: s.lat, lng: s.lng }))
|
||||
}, [day, routes.days, dayId])
|
||||
/**
|
||||
* The day's stored stops, in their stored order, wherever the cards draw them.
|
||||
*
|
||||
* A via is filed behind a stored stop, by its index (`legs` in the plan is that index),
|
||||
* so the track is fitted between those and nothing else: not the markers a day window
|
||||
* adds, not a terminal and not the hotel a day starts or ends at, each of which would
|
||||
* shift every via behind it one leg on. Read across every card because a night drive
|
||||
* draws some of them on the next one.
|
||||
*/
|
||||
const stops = useMemo<LatLng[]>(() => routes.days
|
||||
.flatMap(d => d.stops)
|
||||
.filter(s => isStoredStop(s) && s.ownerDayId === dayId)
|
||||
.sort((a, b) => a.ownerIndex - b.ownerIndex)
|
||||
.map(s => ({ lat: s.lat, lng: s.lng })), [routes.days, dayId])
|
||||
|
||||
/**
|
||||
* Parsed only while the dialog is open.
|
||||
|
||||
Reference in New Issue
Block a user