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): a tour opens in a sheet instead of the desktop dialog

Maurice2aa25e3fe752
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<DetailShellProps>;
}
/** 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 (
- <DetailShell
+ <Shell
testId="tour-detail"
header={header}
footer={footer}
@@ -797,7 +800,7 @@ export default function TourDetailDialog({
<TourProvenanceBlock tripId={place.trip_id} tour={tour} canCheck={canEdit} onReimported={onSourceReimported} />
<TourFilesSection placeId={place.id} files={placeFiles} onFileUpload={canEdit ? onFileUpload : undefined} />
- </DetailShell>
+ </Shell>
);
}
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 (
+ <MSheet open={open} onClose={onClose} variant="card" material="glass" ariaLabel={label || closeLabel}>
+ <div className="flex flex-none items-start gap-3 px-[18px] pt-4">
+ {header}
+ <MIconBtn variant="neutral" size={34} onClick={onClose} ariaLabel={closeLabel}>
+ <X size={15} strokeWidth={2.2} />
+ </MIconBtn>
+ </div>
+ <div
+ data-testid={testId}
+ className="m-scroll-fade mt-2 flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto px-[18px] pb-[18px] pt-[14px]"
+ >
+ {children}
+ </div>
+ {footer && (
+ <div className="flex flex-none flex-wrap items-center gap-2 border-t border-[color:var(--m-rowbr)] px-[18px] pb-4 pt-3">
+ {footer}
+ </div>
+ )}
+ </MSheet>
+ );
+}
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<MTripSheetsProps, 'planner'>) {
- const panelRef = useRef<HTMLDivElement>(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])
-
- if (!planner.selectedTour || !planner.selectedPlace) return null
+ const open = !!(planner.selectedTour && planner.selectedPlace)
+ const tour = useLastOpen(planner.selectedTour, open)
+ const place = useLastOpen(planner.selectedPlace, open)
+ if (!tour || !place) return null
- return createPortal(
- <div className="bg-[rgba(0,0,0,0.3)]" style={{ position: 'fixed', inset: 0, zIndex: 9999, display: 'flex', alignItems: 'flex-end', justifyContent: 'center', paddingBottom: 'var(--bottom-nav-h)' }} role="presentation" onClick={() => planner.setSelectedPlaceId(null)}>
- <div ref={panelRef} style={{ width: '100%', maxHeight: '85vh' }} role="dialog" aria-modal="true" aria-label={planner.selectedPlace.name}
- data-m-sheet="open"
- tabIndex={-1} onClick={event => event.stopPropagation()} onKeyDown={event => trapTab(event, panelRef.current!)}>
- <TourDetailDialog
- tour={planner.selectedTour}
- place={planner.selectedPlace}
- days={planner.days}
- selectedDayId={planner.selectedDayId}
- selectedAssignmentId={planner.selectedAssignmentId}
- assignments={planner.assignments}
- files={planner.files}
- readOnly
- canEdit={false}
- canAssign={planner.can('day_edit', planner.trip)}
- onClose={() => planner.setSelectedPlaceId(null)}
- onAssignToDay={planner.handleAssignToDay}
- onRemoveAssignment={planner.handleRemoveAssignment}
- />
- </div>
- </div>,
- document.body,
+ return (
+ <TourSheetOpen.Provider value={{ open, label: place.name }}>
+ <TourDetailDialog
+ shell={MTourDetailShell}
+ tour={tour}
+ place={place}
+ days={planner.days}
+ selectedDayId={planner.selectedDayId}
+ selectedAssignmentId={planner.selectedAssignmentId}
+ assignments={planner.assignments}
+ files={planner.files}
+ readOnly
+ canEdit={false}
+ canAssign={planner.can('day_edit', planner.trip)}
+ onClose={() => planner.setSelectedPlaceId(null)}
+ onAssignToDay={planner.handleAssignToDay}
+ onRemoveAssignment={planner.handleRemoveAssignment}
+ />
+ </TourSheetOpen.Provider>
)
}