Files
TREK/client/src/components/Roadtrip/useHotelBookends.ts
T
Maurice 7e7d13c021 feat(roadtrip): a day after a booked night starts at the stay, a day before one ends there
A trip can now switch on roadtrip_hotel_bookends, a shared driving preference that is off
until somebody sets it, so every trip drives exactly as before. Switched on, the planner in
the browser and calculate_roadtrip on the server seat the hotel slept in at the start of the
next day and tonight's hotel at the end of the day, both through seatNightBookends over the
trip's stays in id order, with the earliest booking linked to each. A linked booking changes
the hotel row and asks the router nothing.

The switch sits in the desktop driving settings under the route line, and the phone's
driving figures carry the same switch as the one control they offer; both write through the
planner's own preference save, so a flip offline queues like any other. get_roadtrip_context
reports the stays, calculate_roadtrip previews the switch through its settings, and the
settings, corridor and day boundary tools say what it does and that missing means off.
2026-09-23 15:31:09 +02:00

31 lines
1.4 KiB
TypeScript

import { hotelBookendsOn } from '@trek/shared/roadtrip'
import { useRoadtripSettings } from '../../hooks/useRoadtripSettings'
/** The preference the switch is stored under, spelled once for both surfaces. */
export const HOTEL_BOOKENDS_KEY = 'roadtrip_hotel_bookends'
/** Whether a trip's days start and end at the stay, and the way to flip it. */
export interface HotelBookendsSwitch {
on: boolean
/** Absent for a reader who may not change it, or while the trip's settings are not in. */
toggle?: () => void
}
/**
* The switch that seats a booked night at both ends of its days, as the desktop settings
* and the phone's driving figures both offer it.
*
* One hook so the two cannot disagree about what "on" means or where it is written. The
* value is the shared rule's own reading (`hotelBookendsOn`: missing is off), the one the
* drive is planned with, and the write is the save the caller holds. On both surfaces that
* is the planner's `saveRoadtripLimit`, so a flip on the phone goes through the same repo,
* the same offline queue and the same broadcast as one on the desktop.
*/
export function useHotelBookends(
save: ((key: string, value: boolean) => void) | undefined,
tripId?: number | string | null,
): HotelBookendsSwitch {
const on = useRoadtripSettings(hotelBookendsOn, tripId)
return { on, toggle: save ? () => save(HOTEL_BOOKENDS_KEY, !on) : undefined }
}