mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +00:00
feat(roadtrip): other ways to drive a leg, on the phone
The desk offers alternative routes from the drive band between two stops; the phone had nothing. A leg in the phone chain now carries one round button that asks the router for other ways and switches to the map, where a bar takes the stage bar's place: the ways as chips with their colour, time, distance and what sets them apart, and a confirm button. On glass there is no hover, so a tap on a chip or on a line only previews that road; confirm writes it. The button shows only where the desk offers it (a routed leg between chosen stops), for someone who may edit the day, and not offline, since vias are written online only. The picker could not have stayed open on a phone at all: the planner closed it whenever road trip mode was off, and that mode is off on a phone by design, so the next render shut it. The close now follows where the picker can be seen (road trip mode on the desk, the road trip tab on a phone), and useRouteAlternatives returns a memoised object. The rules both shells need are shared: legReroutable in the row model, alternativesPhase and alternativeSubline next to the overlays, and the desk bar and sidebar read them too with no visible change. Both map engines take an optional fitPadding, so the phone frames the leg between the day chips and the bar instead of under them.
This commit is contained in:
@@ -12,7 +12,7 @@ import type { RoadtripStop } from './useRoadtripRoutes'
|
||||
import type { RoadtripVia } from '@trek/shared'
|
||||
|
||||
/**
|
||||
* FE-ALTHOOK-001..009 — asking for other ways of driving one leg.
|
||||
* FE-ALTHOOK-001..010: asking for other ways of driving one leg.
|
||||
*
|
||||
* The case that carries the feature: when the leg already carries vias, the road
|
||||
* actually being driven is NOT among what the router offers for the two bare
|
||||
@@ -147,4 +147,25 @@ describe('useRouteAlternatives', () => {
|
||||
expect(signals[1].aborted).toBe(true)
|
||||
expect(result.current.open).toBeNull()
|
||||
})
|
||||
|
||||
it('FE-ALTHOOK-010: the state keeps its identity until the picker itself changes', async () => {
|
||||
// The planner keys its close gate on this object. A new one per render ran that
|
||||
// effect on every render, so any render at all was a chance to close the picker.
|
||||
const { result, rerender } = renderHook(() => useRouteAlternatives())
|
||||
const idle = result.current
|
||||
rerender()
|
||||
expect(result.current).toBe(idle)
|
||||
|
||||
act(() => { result.current.ask(4, 1, from, to, 'driving', []) })
|
||||
const asking = result.current
|
||||
expect(asking).not.toBe(idle)
|
||||
// The functions themselves never change, only the object carrying the new `open`.
|
||||
expect(asking.ask).toBe(idle.ask)
|
||||
expect(asking.close).toBe(idle.close)
|
||||
|
||||
await waitFor(() => expect(result.current.open?.loading).toBe(false))
|
||||
const answered = result.current
|
||||
rerender()
|
||||
expect(result.current).toBe(answered)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user