Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(mobile): line the day rail up on today once the trip splash lifts

Mauricec03c40d28765
diff --git a/client/src/mobile/screens/trip/MTripShell.tsx b/client/src/mobile/screens/trip/MTripShell.tsx
index 6f67bc27f..477d302f4 100644
--- a/client/src/mobile/screens/trip/MTripShell.tsx
+++ b/client/src/mobile/screens/trip/MTripShell.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useRef, useState, type ComponentType, type ReactNode } from 'react'
+import { useEffect, useLayoutEffect, useRef, useState, type ComponentType, type ReactNode } from 'react'
import { findFocusDayId, findTodayDayId } from '../../../components/Planner/today'
import { takeResumeDay } from '../../../utils/resumeRoute'
import {
@@ -266,22 +266,29 @@ export default function MTripShell({
// screen — the rail overflows from roughly six days on — so the active chip
// pulls itself back into view. Only when it is really clipped, so tapping a
// chip you can already see never shifts the rail under your thumb.
+ // The opening day is chosen while the splash still covers the shell (#2880),
+ // so the rail itself is a dependency: the chip is lined up when the rail
+ // appears, in place rather than gliding across a rail nobody has seen yet.
const chipRefs = useRef(new Map<number, HTMLButtonElement>())
- useEffect(() => {
+ const [dayRail, setDayRail] = useState<HTMLDivElement | null>(null)
+ const alignedRailRef = useRef<HTMLDivElement | null>(null)
+ useLayoutEffect(() => {
const chip = planner.selectedDayId != null ? chipRefs.current.get(planner.selectedDayId) : undefined
- const rail = chip?.parentElement
- if (!chip || !rail) return
+ if (!chip || !dayRail) return
+ const firstView = alignedRailRef.current !== dayRail
+ alignedRailRef.current = dayRail
const c = chip.getBoundingClientRect()
- const r = rail.getBoundingClientRect()
+ const r = dayRail.getBoundingClientRect()
if (c.left >= r.left - 1 && c.right <= r.right + 1) return
+ const reducedMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches
// block:'nearest' is not optional: the shell root is `fixed inset-0`, and
// 'center' would scroll the document behind it instead.
chip.scrollIntoView({
- behavior: window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches ? 'auto' : 'smooth',
+ behavior: firstView || reducedMotion ? 'auto' : 'smooth',
inline: 'center',
block: 'nearest',
})
- }, [planner.selectedDayId, days])
+ }, [planner.selectedDayId, days, dayRail])
const trTab = planner.activeTab
@@ -491,7 +498,7 @@ export default function MTripShell({
{/* ── Day chips (z-25 — covered by non-plan tab overlays, stays mounted) ── */}
{days.length > 0 && (
<div className="absolute inset-x-4 z-[25] flex gap-[6px] top-[calc(var(--m-safe-top,12px)+50px)]">
- <div className="flex flex-1 items-center gap-[2px] overflow-x-auto rounded-full border border-[color:var(--m-gbr)] bg-[color:var(--m-glass)] p-[3px] backdrop-blur-[24px] backdrop-saturate-[1.7]">
+ <div ref={setDayRail} className="flex flex-1 items-center gap-[2px] overflow-x-auto rounded-full border border-[color:var(--m-gbr)] bg-[color:var(--m-glass)] p-[3px] backdrop-blur-[24px] backdrop-saturate-[1.7]">
{days.map((day, idx) => {
const active = day.id === planner.selectedDayId
const isToday = day.id === todayDayId
diff --git a/client/tests/unit/mobile/trip/MTripShell.test.tsx b/client/tests/unit/mobile/trip/MTripShell.test.tsx
index 3c5792233..085e79b57 100644
--- a/client/tests/unit/mobile/trip/MTripShell.test.tsx
+++ b/client/tests/unit/mobile/trip/MTripShell.test.tsx
@@ -569,14 +569,70 @@ describe('MTripShell', () => {
afterEach(() => { vi.restoreAllMocks() })
- it('FE-MOB-SHELL-044: a clipped active chip pulls itself into the middle of the rail', () => {
+ it('FE-MOB-SHELL-044: a clipped active chip is in the middle of the rail the moment it appears', () => {
const scrollIntoView = vi.mocked(Element.prototype.scrollIntoView)
scrollIntoView.mockClear()
stubRects({ left: 480, right: 540 })
renderShell({ selectedDayId: 12 } as Partial<TripPlanner>)
+ expect(scrollIntoView).toHaveBeenCalledWith({ behavior: 'auto', inline: 'center', block: 'nearest' })
+ })
+
+ it('FE-MOB-SHELL-093: a later day change on the rail glides to the chip', () => {
+ const scrollIntoView = vi.mocked(Element.prototype.scrollIntoView)
+ stubRects({ left: 480, right: 540 })
+ const { planner, rerenderShell } = renderShell({ selectedDayId: 11 } as Partial<TripPlanner>)
+ scrollIntoView.mockClear()
+
+ ;(planner as { selectedDayId: number | null }).selectedDayId = 12
+ rerenderShell()
+
+ expect(scrollIntoView).toHaveBeenCalledTimes(1)
expect(scrollIntoView).toHaveBeenCalledWith({ behavior: 'smooth', inline: 'center', block: 'nearest' })
})
+ // #2880: the day is seeded while the splash still covers the shell, so the
+ // rail only exists after the selection has settled.
+ it('FE-MOB-SHELL-094: the active day is brought into view once the splash lifts (#2880)', () => {
+ const scrollIntoView = vi.mocked(Element.prototype.scrollIntoView)
+ scrollIntoView.mockClear()
+ stubRects({ left: 480, right: 540 })
+ const { planner, rerenderShell } = renderShell({ selectedDayId: 12, splashDone: false } as Partial<TripPlanner>)
+ expect(scrollIntoView).not.toHaveBeenCalled()
+
+ ;(planner as { splashDone: boolean }).splashDone = true
+ rerenderShell()
+
+ expect(scrollIntoView).toHaveBeenCalledTimes(1)
+ expect(scrollIntoView).toHaveBeenCalledWith({ behavior: 'auto', inline: 'center', block: 'nearest' })
+ })
+
+ it('FE-MOB-SHELL-095: after the splash a chip already in view leaves the rail alone', () => {
+ const scrollIntoView = vi.mocked(Element.prototype.scrollIntoView)
+ scrollIntoView.mockClear()
+ stubRects({ left: 40, right: 100 })
+ const { planner, rerenderShell } = renderShell({ selectedDayId: 12, splashDone: false } as Partial<TripPlanner>)
+
+ ;(planner as { splashDone: boolean }).splashDone = true
+ rerenderShell()
+
+ expect(scrollIntoView).not.toHaveBeenCalled()
+ })
+
+ it('FE-MOB-SHELL-096: re-entering the trip lines the rail up again without a glide', () => {
+ const scrollIntoView = vi.mocked(Element.prototype.scrollIntoView)
+ stubRects({ left: 480, right: 540 })
+ const { planner, rerenderShell } = renderShell({ selectedDayId: 12 } as Partial<TripPlanner>)
+
+ ;(planner as { isLoading: boolean }).isLoading = true
+ rerenderShell()
+ scrollIntoView.mockClear()
+ ;(planner as { isLoading: boolean }).isLoading = false
+ rerenderShell()
+
+ expect(scrollIntoView).toHaveBeenCalledTimes(1)
+ expect(scrollIntoView).toHaveBeenCalledWith({ behavior: 'auto', inline: 'center', block: 'nearest' })
+ })
+
it('FE-MOB-SHELL-045: a chip already in view never shifts the rail under the thumb', () => {
const scrollIntoView = vi.mocked(Element.prototype.scrollIntoView)
scrollIntoView.mockClear()