From 2aa25e3fe7522c6a38059be03146693a0e3e1719 Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 6 Nov 2026 16:22:23 +0100 Subject: [PATCH] fix(mobile): a tour opens in a sheet instead of the desktop dialog A tour tapped in the plan opened the desktop detail dialog in a hand-built overlay: no slide, no drag to close, the desktop's frame on a phone. The dialog now renders into the frame it is given; on the phone that is a sheet like every other detail (MTourDetailShell), with the tour's name as its title, its whole content and every action, the back gesture and an exit animation. --- client/scripts/theme-baseline.json | 3 +- .../src/components/Tours/TourDetailDialog.tsx | 11 ++- client/src/components/shared/DetailShell.tsx | 2 +- .../screens/trip/sheets/MTourDetailShell.tsx | 42 ++++++++++ .../screens/trip/sheets/MTripSheets.test.tsx | 2 +- .../screens/trip/sheets/MTripSheets.tsx | 83 +++++++------------ 6 files changed, 82 insertions(+), 61 deletions(-) create mode 100644 client/src/mobile/screens/trip/sheets/MTourDetailShell.tsx diff --git a/client/scripts/theme-baseline.json b/client/scripts/theme-baseline.json index 0dd0fddee..32181e17e 100644 --- a/client/scripts/theme-baseline.json +++ b/client/scripts/theme-baseline.json @@ -251,11 +251,10 @@ "mobile/screens/trip/sheets/MTransportFormSheet.tsx": 9, "mobile/screens/trip/sheets/MTransportSheet.tsx": 12, "mobile/screens/trip/sheets/MTripSheetUi.tsx": 5, - "mobile/screens/trip/sheets/MTripSheets.tsx": 2, "mobile/screens/trip/sheets/PlCategoryPicker.tsx": 2, "mobile/screens/trip/sheets/PlFileAttach.tsx": 7, "mobile/screens/trip/sheets/PlPlaceSearch.tsx": 6, - "mobile/screens/trip/sheets/PlSheetChrome.tsx": 7, + "mobile/screens/trip/sheets/PlSheetChrome.tsx": 5, "mobile/screens/trip/sheets/PlTimeFields.tsx": 3, "mobile/screens/trip/tabs/MBagsSheet.tsx": 13, "mobile/screens/trip/tabs/MBookingsTab.tsx": 2, diff --git a/client/src/components/Tours/TourDetailDialog.tsx b/client/src/components/Tours/TourDetailDialog.tsx index 6602909f9..16480cba4 100644 --- a/client/src/components/Tours/TourDetailDialog.tsx +++ b/client/src/components/Tours/TourDetailDialog.tsx @@ -22,7 +22,7 @@ import { Ruler, Upload, } from 'lucide-react'; -import { createElement, useEffect, useMemo, useRef, useState } from 'react'; +import { createElement, useEffect, useMemo, useRef, useState, type ComponentType } from 'react'; import Markdown from 'react-markdown'; import remarkBreaks from 'remark-breaks'; import remarkGfm from 'remark-gfm'; @@ -38,7 +38,7 @@ import { inheritedTrackColor, resolveTrackColor } from '../Map/trackColors'; import { BOX } from '../Planner/bookings/bookingParts'; import { getNavigationTargets, navigationTargetLabel, openNavigationTarget } from '../Planner/placeNavigation'; import { SoftPill, tintOf } from '../Planner/planParts'; -import DetailShell from '../shared/DetailShell'; +import DetailShell, { type DetailShellProps } from '../shared/DetailShell'; import { DeleteButton, DialogButton, DialogSection, FooterSpacer, fs } from '../shared/DialogShell'; import ElevationProfile from '../shared/ElevationProfile'; import { NavigationMenu } from '../shared/NavigationMenu'; @@ -108,6 +108,8 @@ interface TourDetailDialogProps extends TourPermissionProps { readOnly?: boolean; /** Desktop-only opener; the map detail stays non-modal and returns focus when closed. */ desktopFocusReturnTarget?: HTMLElement | null; + /** The frame it renders into: the desktop's card over the map, or the phone's sheet. */ + shell?: ComponentType; } /** The pills of the head band: white like a place's, one fact each. */ @@ -518,6 +520,7 @@ export default function TourDetailDialog({ desktopNonModal = false, readOnly = false, desktopFocusReturnTarget = null, + shell: Shell = DetailShell, canEdit: editPermission, canAssign: assignPermission, }: TourDetailDialogProps) { @@ -701,7 +704,7 @@ export default function TourDetailDialog({ ); return ( - - + ); } diff --git a/client/src/components/shared/DetailShell.tsx b/client/src/components/shared/DetailShell.tsx index 47c4c144e..589b1125a 100644 --- a/client/src/components/shared/DetailShell.tsx +++ b/client/src/components/shared/DetailShell.tsx @@ -4,7 +4,7 @@ import { NEUTRAL_TINT } from './DialogShell' import { Tooltip } from './Tooltip' import { centredMapCard } from '../Map/centredMapCard' -interface DetailShellProps { +export interface DetailShellProps { header: ReactNode children: ReactNode footer?: ReactNode diff --git a/client/src/mobile/screens/trip/sheets/MTourDetailShell.tsx b/client/src/mobile/screens/trip/sheets/MTourDetailShell.tsx new file mode 100644 index 000000000..181337324 --- /dev/null +++ b/client/src/mobile/screens/trip/sheets/MTourDetailShell.tsx @@ -0,0 +1,42 @@ +import { X } from 'lucide-react'; +import { createContext, useContext } from 'react'; +import type { DetailShellProps } from '../../../../components/shared/DetailShell'; +import MIconBtn from '../../../components/MIconBtn'; +import MSheet from '../../../components/MSheet'; + +/** + * Whether the tour sheet is open (false while it slides away with the tour it + * showed last) and the tour's name, which names the dialog. + */ +export const TourSheetOpen = createContext<{ open: boolean; label: string }>({ open: true, label: '' }); + +/** + * The phone's frame for the tour detail: the desktop dialog's head, sections + * and actions in a sheet like every other one (TourDetailDialog renders into + * the frame it is given). It slides in and out, drags closed, closes on the + * back gesture and keeps the tour's whole content and every action. + */ +export default function MTourDetailShell({ header, children, footer, onClose, closeLabel, testId }: DetailShellProps) { + const { open, label } = useContext(TourSheetOpen); + return ( + +
+ {header} + + + +
+
+ {children} +
+ {footer && ( +
+ {footer} +
+ )} +
+ ); +} diff --git a/client/src/mobile/screens/trip/sheets/MTripSheets.test.tsx b/client/src/mobile/screens/trip/sheets/MTripSheets.test.tsx index 615288ea9..b09f6725b 100644 --- a/client/src/mobile/screens/trip/sheets/MTripSheets.test.tsx +++ b/client/src/mobile/screens/trip/sheets/MTripSheets.test.tsx @@ -65,7 +65,7 @@ beforeEach(() => { }) describe('MSelectedTourDetail', () => { - it('is the single mobile modal owner for Escape, focus containment, scroll lock and focus return', () => { + it('shows the tour in a mobile sheet that owns Escape, focus containment, scroll lock and focus return', () => { const opener = document.createElement('button') opener.textContent = 'Open mobile Tour' document.body.appendChild(opener) diff --git a/client/src/mobile/screens/trip/sheets/MTripSheets.tsx b/client/src/mobile/screens/trip/sheets/MTripSheets.tsx index a67bc01ee..0403a05b0 100644 --- a/client/src/mobile/screens/trip/sheets/MTripSheets.tsx +++ b/client/src/mobile/screens/trip/sheets/MTripSheets.tsx @@ -1,5 +1,3 @@ -import { useEffect, useRef } from 'react' -import { createPortal } from 'react-dom' import TransitJourneyModal from '../../../../components/Planner/TransitJourneyModal' import BookingImportModal from '../../../../components/Planner/BookingImportModal' import AirTrailImportModal from '../../../../components/Planner/AirTrailImportModal' @@ -34,60 +32,39 @@ import MRtInfoSheet from '../roadtrip/MRtInfoSheet' import MRtCorridorSheet from '../roadtrip/MRtCorridorSheet' import MRtDraftSheet from '../roadtrip/MRtDraftSheet' import type { MTripSheetsProps } from '../MTripShell' -import { lockBodyScroll } from '../../../../utils/bodyScrollLock' -import { focusDialog, trapTab } from '../../../../components/shared/dialogFocus' +import MTourDetailShell, { TourSheetOpen } from './MTourDetailShell' +import { useLastOpen } from '../../../../components/shared/usePresence' -/** The one global mobile tour-detail owner, independent of which surface selected it. */ +/** + * The one global mobile tour-detail owner, independent of which surface + * selected it. The tour shows in a sheet like every other detail + * (MTourDetailShell); it keeps the tour it showed last while it slides away. + */ export function MSelectedTourDetail({ planner }: Pick) { - const panelRef = useRef(null) - const selectedTourId = planner.selectedTour?.place_id ?? null - const selectedPlaceId = planner.selectedPlace?.id ?? null - useEffect(() => { - if (selectedTourId == null || selectedPlaceId == null) return - const previous = document.activeElement as HTMLElement | null - const release = lockBodyScroll() - const panel = panelRef.current - if (panel) focusDialog(panel) - const onKeyDown = (event: KeyboardEvent) => { - if (event.key !== 'Escape' || event.defaultPrevented) return - const openPanels = document.querySelectorAll('[data-m-sheet="open"]') - if (openPanels.length && openPanels[openPanels.length - 1] !== panel) return - event.preventDefault() - planner.setSelectedPlaceId(null) - } - document.addEventListener('keydown', onKeyDown) - return () => { - document.removeEventListener('keydown', onKeyDown) - release() - if (previous?.isConnected) previous.focus() - } - }, [planner.setSelectedPlaceId, selectedPlaceId, selectedTourId]) + const open = !!(planner.selectedTour && planner.selectedPlace) + const tour = useLastOpen(planner.selectedTour, open) + const place = useLastOpen(planner.selectedPlace, open) + if (!tour || !place) return null - if (!planner.selectedTour || !planner.selectedPlace) return null - - return createPortal( -
planner.setSelectedPlaceId(null)}> -
event.stopPropagation()} onKeyDown={event => trapTab(event, panelRef.current!)}> - planner.setSelectedPlaceId(null)} - onAssignToDay={planner.handleAssignToDay} - onRemoveAssignment={planner.handleRemoveAssignment} - /> -
-
, - document.body, + return ( + + planner.setSelectedPlaceId(null)} + onAssignToDay={planner.handleAssignToDay} + onRemoveAssignment={planner.handleRemoveAssignment} + /> + ) }