From faaa56eda6d9193c43bc3add987721c75882bbdf Mon Sep 17 00:00:00 2001 From: Maurice Date: Thu, 3 Dec 2026 23:30:26 +0100 Subject: [PATCH] fix(mobile): harden back gestures and repair CI regressions Reflect the drag position in the sheet scrim and match back gestures to the reading direction. Keep Escape on the top overlay and update failing tests for the redesigned forms, navigation, and offline preparation. Remove dead exports and lower obsolete lint counts. --- client/scripts/eslint-baseline.json | 12 +++--- .../Dawarich/DawarichAcceptDialog.test.tsx | 6 +-- .../Journey/ContributorInviteDialog.tsx | 2 +- client/src/components/Layout/navItems.test.ts | 4 +- .../Planner/BookingImportModal.test.tsx | 2 +- .../Settings/useMobileNavEditor.test.tsx | 4 +- client/src/hooks/overlayStack.ts | 4 +- .../src/mobile/components/MEdgeBack.test.tsx | 29 ++++++++++++++ client/src/mobile/components/MEdgeBack.tsx | 36 +++++++++++------ client/src/mobile/components/MSheet.tsx | 21 +++++++--- client/src/mobile/components/useSheetDrag.ts | 11 +++++- .../screens/collections/MCollAddSheet.tsx | 3 +- .../screens/collections/MCollSavedFilters.tsx | 9 ----- .../screens/collections/MCollShareSheet.tsx | 3 +- .../mobile/screens/collections/MCollTours.tsx | 5 +-- .../screens/collections/MCollections.tsx | 3 +- .../collections/collectionsMobileModel.ts | 6 --- .../collections/savedListFilterCount.ts | 10 +++++ .../screens/journey/MJourneyEntrySheet.tsx | 3 +- .../screens/journey/MJourneyInviteFrame.tsx | 5 +-- .../trip/places/MPlacesFilterControls.tsx | 2 +- .../screens/trip/roadtrip/stageBookings.ts | 2 +- .../screens/trip/sheets/ImpListStep.tsx | 3 +- .../screens/trip/sheets/MTripSheetUi.tsx | 39 ------------------- .../screens/trip/sheets/PlSheetChrome.tsx | 6 --- .../screens/trip/sheets/formOptionClass.ts | 5 +++ .../mobile/screens/trip/tabs/MBookingsTab.tsx | 3 +- .../mobile/screens/trip/tabs/MCollabNotes.tsx | 3 +- .../mobile/screens/trip/tabs/MCostsTab.tsx | 3 +- .../trip/tabs/MReservationCardParts.tsx | 4 -- .../screens/trip/tabs/MTransportsTab.tsx | 3 +- .../trip/tabs/reservationHeaderTint.ts | 3 ++ .../screens/vacay/MVacayInviteSheet.tsx | 4 +- .../screens/vacay/MVacaySettingsSheet.tsx | 15 +++++-- .../mobile/screens/vacay/MVacayShareSheet.tsx | 4 +- .../src/sync/tripSyncManager.prepare.test.ts | 2 +- client/tests/unit/mobile/MSheet.test.tsx | 18 ++++++--- client/tests/unit/mobile/formSheet.test.tsx | 3 +- client/tests/unit/mobile/largeScreen.test.tsx | 7 ++-- 39 files changed, 171 insertions(+), 136 deletions(-) create mode 100644 client/src/mobile/screens/collections/savedListFilterCount.ts create mode 100644 client/src/mobile/screens/trip/sheets/formOptionClass.ts create mode 100644 client/src/mobile/screens/trip/tabs/reservationHeaderTint.ts diff --git a/client/scripts/eslint-baseline.json b/client/scripts/eslint-baseline.json index ce43816a4..c84f4d998 100644 --- a/client/scripts/eslint-baseline.json +++ b/client/scripts/eslint-baseline.json @@ -1,21 +1,21 @@ { "src": { - "@typescript-eslint/no-non-null-assertion": 345, - "@typescript-eslint/no-misused-promises": 810, - "no-console": 85, + "@typescript-eslint/no-non-null-assertion": 338, + "@typescript-eslint/no-misused-promises": 750, + "no-console": 81, "complexity": 214, "@typescript-eslint/no-explicit-any": 113, "trek/no-swallowed-catch": 124, "max-params": 31, "trek/store-without-selector": 65, - "react-hooks/refs": 384, + "react-hooks/refs": 380, "react-hooks/set-state-in-effect": 188, - "@typescript-eslint/no-floating-promises": 162, + "@typescript-eslint/no-floating-promises": 156, "react-hooks/exhaustive-deps": 112, "@typescript-eslint/no-unused-vars": 95, "react-hooks/immutability": 26, "max-lines-per-function": 126, - "react-hooks/static-components": 38, + "react-hooks/static-components": 35, "react-hooks/preserve-manual-memoization": 12, "no-useless-assignment": 7, "no-empty": 18, diff --git a/client/src/components/Dawarich/DawarichAcceptDialog.test.tsx b/client/src/components/Dawarich/DawarichAcceptDialog.test.tsx index c4baaa362..aa6b2a6a5 100644 --- a/client/src/components/Dawarich/DawarichAcceptDialog.test.tsx +++ b/client/src/components/Dawarich/DawarichAcceptDialog.test.tsx @@ -440,9 +440,9 @@ describe('DawarichAcceptDialog', () => { phone.value = true const { onConfirm } = open({ trips: TRIPS, daysForTrip }) - expect(screen.getByRole('dialog', { name: 'Add this stay as a place' })).toBeInTheDocument() - // The desktop modal's own heading is the tell that the wrong shell rendered. - expect(screen.queryByRole('heading', { name: 'Add this stay as a place' })).toBeNull() + const sheet = screen.getByRole('dialog', { name: 'Add this stay as a place' }) + expect(sheet).toHaveAttribute('data-m-sheet', 'open') + expect(screen.getByRole('heading', { name: 'Add this stay as a place' })).toBeInTheDocument() fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'Reichard' } }) fireEvent.click(screen.getByRole('button', { name: 'Add place' })) diff --git a/client/src/components/Journey/ContributorInviteDialog.tsx b/client/src/components/Journey/ContributorInviteDialog.tsx index a3e32cc22..ebb73ce88 100644 --- a/client/src/components/Journey/ContributorInviteDialog.tsx +++ b/client/src/components/Journey/ContributorInviteDialog.tsx @@ -52,7 +52,7 @@ export default function ContributorInviteDialog({ journeyId, existingUserIds, on const toast = useToast() useEffect(() => { - authApi.listUsers().then(d => setUsers(d.users || [])).catch(() => {}).finally(() => setLoading(false)) + authApi.listUsers().then(d => setUsers(d.users || [])).catch(() => setUsers([])).finally(() => setLoading(false)) }, []) // Captured and stopped on the desktop: the dialog is usually opened from the diff --git a/client/src/components/Layout/navItems.test.ts b/client/src/components/Layout/navItems.test.ts index a3dd9899e..c2d9c4489 100644 --- a/client/src/components/Layout/navItems.test.ts +++ b/client/src/components/Layout/navItems.test.ts @@ -28,9 +28,9 @@ describe('splitMobileNav', () => { it('docks the top two enabled defaults when there is no config', () => { for (const cfg of [undefined, { bar: [], more: [] }]) { const s = splitMobileNav(items, cfg) - expect(ids(s.bar)).toEqual(['dashboard', 'vacay', 'journey']) + expect(ids(s.bar)).toEqual(['dashboard', 'collections', 'journey']) // Atlas is still reachable, one tap further under More. - expect(ids(s.more)).toEqual(['atlas', 'collections']) + expect(ids(s.more)).toEqual(['vacay', 'atlas']) } }) diff --git a/client/src/components/Planner/BookingImportModal.test.tsx b/client/src/components/Planner/BookingImportModal.test.tsx index 5bd985c63..e304e9cd0 100644 --- a/client/src/components/Planner/BookingImportModal.test.tsx +++ b/client/src/components/Planner/BookingImportModal.test.tsx @@ -43,7 +43,7 @@ describe('BookingImportModal', () => { const upload = vi.fn(() => HttpResponse.json({ jobId: 'mobile-pdf' })); server.use(http.post('/api/trips/4/reservations/import/booking/async', upload)); render(); - expect(screen.getByRole('dialog', { name: 'Import booking confirmations' })).toBeInTheDocument(); + expect(screen.getByRole('dialog', { name: 'Import from file' })).toBeInTheDocument(); await userEvent.upload(fileInput(), [pdf, eml()]); await userEvent.click(screen.getByRole('button', { name: 'Remove: booking.eml' })); const submit = screen.getByRole('button', { name: 'Import' }); diff --git a/client/src/components/Settings/useMobileNavEditor.test.tsx b/client/src/components/Settings/useMobileNavEditor.test.tsx index 6dfe0f065..d7e0cd9cf 100644 --- a/client/src/components/Settings/useMobileNavEditor.test.tsx +++ b/client/src/components/Settings/useMobileNavEditor.test.tsx @@ -38,8 +38,8 @@ describe('useMobileNavEditor', () => { it('FE-COMP-NAVEDITOR-001: an empty value falls back to the built-in dock split', () => { const { result } = setup({ bar: [], more: [] }); - expect(ids(result.current.barItems)).toEqual(['vacay', 'journey']); - expect(ids(result.current.moreItems)).toEqual(['atlas', 'collections']); + expect(ids(result.current.barItems)).toEqual(['collections', 'journey']); + expect(ids(result.current.moreItems)).toEqual(['vacay', 'atlas']); expect(result.current.hasMore).toBe(true); expect(result.current.barFull).toBe(true); }); diff --git a/client/src/hooks/overlayStack.ts b/client/src/hooks/overlayStack.ts index 8d6d8ed08..85702cd6d 100644 --- a/client/src/hooks/overlayStack.ts +++ b/client/src/hooks/overlayStack.ts @@ -57,9 +57,9 @@ export function useOverlay(open: boolean, close: Close, dismissOnEscape = false) event.stopPropagation(); entry.close(); }; - if (dismissOnEscape) document.addEventListener('keydown', onKey, true); + if (dismissOnEscape) window.addEventListener('keydown', onKey, true); return () => { - if (dismissOnEscape) document.removeEventListener('keydown', onKey, true); + if (dismissOnEscape) window.removeEventListener('keydown', onKey, true); const i = stack.findIndex((e) => e.id === entry.id); if (i >= 0) stack.splice(i, 1); entryId.current = null; diff --git a/client/src/mobile/components/MEdgeBack.test.tsx b/client/src/mobile/components/MEdgeBack.test.tsx index a08092ca5..9eb330876 100644 --- a/client/src/mobile/components/MEdgeBack.test.tsx +++ b/client/src/mobile/components/MEdgeBack.test.tsx @@ -33,11 +33,40 @@ beforeEach(() => { Object.defineProperty(window, 'innerWidth', { configurable: true, value: 400 }); }); afterEach(() => { + document.documentElement.removeAttribute('dir'); vi.useRealTimers(); vi.clearAllMocks(); }); describe('MEdgeBack', () => { + it('mirrors the swipe from the right edge in a right-to-left interface', () => { + document.documentElement.dir = 'rtl'; + const back = vi.spyOn(window.history, 'back').mockImplementation(() => {}); + const { getByTestId } = render(); + + touch('touchstart', 395, 300, 0); + touch('touchmove', 220, 300, 100); + expect(getByTestId('page').style.transform).toBe('translateX(-175px)'); + + touch('touchend', 220, 300, 150); + vi.advanceTimersByTime(280); + expect(back).toHaveBeenCalledTimes(1); + }); + + it('drops a scheduled back navigation if the history changes first', () => { + const back = vi.spyOn(window.history, 'back').mockImplementation(() => {}); + const { getByTestId } = render(); + + touch('touchstart', 5, 300, 0); + touch('touchmove', 200, 300, 100); + touch('touchend', 200, 300, 150); + window.dispatchEvent(new PopStateEvent('popstate')); + vi.advanceTimersByTime(280); + + expect(getByTestId('page').style.transform).toBe(''); + expect(back).not.toHaveBeenCalled(); + }); + it('drags the page with a finger from the left edge, and goes back past a third', () => { const back = vi.spyOn(window.history, 'back').mockImplementation(() => {}); const { getByTestId } = render(); diff --git a/client/src/mobile/components/MEdgeBack.tsx b/client/src/mobile/components/MEdgeBack.tsx index dcfd6cca7..ae1414bc0 100644 --- a/client/src/mobile/components/MEdgeBack.tsx +++ b/client/src/mobile/components/MEdgeBack.tsx @@ -12,7 +12,7 @@ import { import { skipNextRouteTransition } from '../routeTransition'; /** - * The swipe from the left edge that goes back, the way every iOS app has it. + * The swipe from the leading edge that goes back on iOS. * * WebKit's own version slides away a screenshot of the whole page, closes no * sheet and fights every gesture near the edge (the day pager, swipe rows), so @@ -23,7 +23,7 @@ import { skipNextRouteTransition } from '../routeTransition'; * the `edgeBack` feature, so an older binary keeps WebKit's. */ -/** A touch has to start this close to the left edge. */ +/** A touch has to start this close to the leading edge. */ const EDGE_PX = 22; /** Sideways must clearly beat vertical before the gesture is claimed. */ const CLAIM_PX = 10; @@ -45,6 +45,8 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject move(0, 'transform 260ms var(--ease-drawer), box-shadow 260ms'); @@ -64,14 +66,24 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject { + window.clearTimeout(navigationTimer); + navigationTimer = undefined; + onCancel(); + move(0, 'none'); + }; + const onStart = (e: TouchEvent) => { onCancel(); if (e.touches.length !== 1) return; const t = e.touches[0]; - if (t.clientX > EDGE_PX) return; if (navigationTimer !== undefined) return; + direction = document.documentElement.dir === 'rtl' ? -1 : 1; + const edgeDistance = direction === 1 ? t.clientX : window.innerWidth - t.clientX; + if (edgeDistance > EDGE_PX) return; overlay = hasOpenOverlay(); if (!overlay && !canGoBack()) return; + reducedMotion = isMotionReduced(); start = { x: t.clientX, y: t.clientY }; samples = [{ position: t.clientX, time: e.timeStamp }]; }; @@ -79,7 +91,7 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject { if (!start || e.touches.length !== 1) return; const t = e.touches[0]; - const dx = t.clientX - start.x; + const dx = direction * (t.clientX - start.x); const dy = t.clientY - start.y; if (!claimed) { if (Math.abs(dy) > CLAIM_PX && Math.abs(dy) > Math.abs(dx)) { @@ -88,12 +100,12 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject { @@ -102,8 +114,8 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject 0 && (dx > width * COMMIT_SHARE || v > FLICK_V); if (!commit) { @@ -115,14 +127,14 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject { navigationTimer = undefined; skipNextRouteTransition(); @@ -136,11 +148,13 @@ export default function MEdgeBack({ target, enabled }: { target: RefObject { document.removeEventListener('touchstart', onStart); document.removeEventListener('touchmove', onMove); document.removeEventListener('touchend', onEnd); document.removeEventListener('touchcancel', onCancel); + window.removeEventListener('popstate', resetNavigation); window.clearTimeout(navigationTimer); cancelAnimationFrame(frame); move(0, 'none'); diff --git a/client/src/mobile/components/MSheet.tsx b/client/src/mobile/components/MSheet.tsx index 306670ad6..9b9718d4a 100644 --- a/client/src/mobile/components/MSheet.tsx +++ b/client/src/mobile/components/MSheet.tsx @@ -215,9 +215,11 @@ export default function MSheet({ // exit animation (which starts from the rest position) must not play. const [flung, setFlung] = useState(false) const panelRef = useRef(null) + const scrimRef = useRef(null) const sheetDrag = useSheetDrag({ enabled: variant === 'bottom' && open && rendered, panelRef, + scrimRef, onDismiss: () => { if (wouldAsk()) { requestClose() @@ -240,6 +242,11 @@ export default function MSheet({ panel.style.transform = '' panel.style.transition = '' } + const scrim = scrimRef.current + if (scrim) { + scrim.style.opacity = '' + scrim.style.transition = '' + } return } setEntered(false) @@ -256,6 +263,9 @@ export default function MSheet({ if (!open || covered) return const onKey = (e: KeyboardEvent) => { if (e.key !== 'Escape' || e.defaultPrevented || !isTop()) return + const openPanels = document.querySelectorAll('[data-m-sheet="open"]') + if (openPanels[openPanels.length - 1] !== panelRef.current) return + e.preventDefault() if (asking) keepEditing() else requestClose() } @@ -293,11 +303,12 @@ export default function MSheet({ if (e.target === e.currentTarget) requestClose() }} > -