From eafb30555c45e7c6d710d80ac3607c3c991213c9 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sun, 8 Nov 2026 11:43:45 +0100 Subject: [PATCH] fix(mobile): the iPad's tour tab opens saved tours, keeps its switch in the top row, and a tap shows no tooltip --- client/scripts/feature-pairs.json | 1 + .../Tours/planner/TourPlannerPanels.tsx | 8 ++- client/src/components/shared/Tooltip.test.tsx | 16 ++++++ client/src/components/shared/Tooltip.tsx | 15 +++++- client/src/mobile/screens/trip/MTripShell.tsx | 6 ++- .../screens/trip/tours/MTourWorkspace.tsx | 52 +++++++++++++------ .../mobile/screens/trip/tours/tourHeadSlot.ts | 34 ++++++++++++ .../src/pages/tripPlanner/b4a-wiring.test.ts | 3 ++ .../src/pages/tripPlanner/useTourWorkspace.ts | 14 +++-- .../unit/mobile/trip/MTourWorkspace.test.tsx | 22 ++++++++ 10 files changed, 145 insertions(+), 26 deletions(-) create mode 100644 client/src/mobile/screens/trip/tours/tourHeadSlot.ts diff --git a/client/scripts/feature-pairs.json b/client/scripts/feature-pairs.json index 2030e4c34..53de49cb5 100644 --- a/client/scripts/feature-pairs.json +++ b/client/scripts/feature-pairs.json @@ -1038,6 +1038,7 @@ "src/mobile/screens/settings/MSettingsUi.tsx": "Phone only settings UI primitives (card, row, input, button, segments, hint).", "src/mobile/screens/settings/MTileCacheUsage.tsx": "Phone only: the native tile cache size and clear action, which the browser build has no counterpart for.", "src/mobile/screens/settings/MWebPushCard.tsx": "Already shares hooks/useWebPush with components/Settings/WebPushCard.tsx.", + "src/mobile/screens/trip/tours/tourHeadSlot.ts": "Phone shell only; the place in the shell's top row the tours tab fills with its switch and map button. The desktop planner heads its rails itself.", "src/mobile/screens/trip/MTripRail.tsx": "Phone shell only; the trip's sections on the leading edge of a wide window in place of the dock, with the tabs and handlers MTripShell hands in.", "src/mobile/screens/trip/MTripShellParts.tsx": "Markup only; small pieces of MTripShell's top controls (segment pill, compact toggle, document sync button), with the state and handlers MTripShell hands in.", "src/mobile/screens/trip/dockTabs.ts": "Phone only helper that picks which trip tabs get a seat in the mobile dock.", diff --git a/client/src/components/Tours/planner/TourPlannerPanels.tsx b/client/src/components/Tours/planner/TourPlannerPanels.tsx index 9b91173b4..7172785f5 100644 --- a/client/src/components/Tours/planner/TourPlannerPanels.tsx +++ b/client/src/components/Tours/planner/TourPlannerPanels.tsx @@ -75,6 +75,8 @@ import { walkTimeFields } from '../walk/walkTimeFields' /** The tinted head band both rails open with, like every panel head in the planner. */ export const RAIL_HEAD = 'flex flex-none items-start gap-2 border-b border-edge-faint px-3 py-2.5' +/** The head as a rounded band of its own, inset like the controls above it (the touch shell's tours tab). */ +const FLOATING_RAIL_HEAD = 'mx-4 mt-1 flex flex-none items-start gap-2 rounded-xl border border-edge-faint px-3 py-2' /** The title of a rail's head band, with an optional line under it. */ export function RailTitle({ title, sub, aside }: { title: string; sub?: ReactNode; aside?: ReactNode }) { @@ -566,6 +568,8 @@ interface TourPlannerToursRailProps extends TourPermissionProps { gpxImport?: TourGpxImport /** LIB-02: takes a tour of another trip in, an entry of "Add tour". */ onTakenOver?: (tour: TourListItem) => Promise + /** The head as a rounded band rather than a ruled one (the touch shell's tours tab). */ + floatingHead?: boolean } /** The words of the time estimate: walking, riding (BIK-01), running (RUN-01) or paddling, each saying how it is reckoned, and a ride none. */ @@ -672,7 +676,7 @@ function stagesFold(tour: TourListItem, rail: ReturnType -
+
{canEdit && }
diff --git a/client/src/components/shared/Tooltip.test.tsx b/client/src/components/shared/Tooltip.test.tsx index cd423e28a..049f29bda 100644 --- a/client/src/components/shared/Tooltip.test.tsx +++ b/client/src/components/shared/Tooltip.test.tsx @@ -223,4 +223,20 @@ describe('Tooltip — with content', () => { expect(tip.querySelectorAll('li')).toHaveLength(2) expect(tip).not.toHaveTextContent('brought by') }) + + it('FE-W4TIP-017: a tap opens nothing, a pointer that comes along later still does', () => { + render() + const button = screen.getByRole('button') + + // The browser follows a tap with a mouseenter and never sends the mouseleave. + fireEvent.touchStart(button) + fireEvent.mouseEnter(button) + act(() => { vi.advanceTimersByTime(300) }) + expect(screen.queryByRole('tooltip')).toBeNull() + + act(() => { vi.advanceTimersByTime(2000) }) + fireEvent.mouseEnter(button) + act(() => { vi.advanceTimersByTime(10) }) + expect(screen.getByRole('tooltip')).toHaveTextContent('Add a tour') + }) }) diff --git a/client/src/components/shared/Tooltip.tsx b/client/src/components/shared/Tooltip.tsx index b236f4aad..6c445fdad 100644 --- a/client/src/components/shared/Tooltip.tsx +++ b/client/src/components/shared/Tooltip.tsx @@ -19,12 +19,22 @@ interface TooltipProps { children: React.ReactElement } +/** The emulated mouse events of a tap follow it within a few hundred milliseconds. */ +const TAP_MOUSE_WINDOW_MS = 1000 + +function touchedRecently(touchedAt: number, now: number): boolean { + return touchedAt > 0 && now - touchedAt < TAP_MOUSE_WINDOW_MS +} + export function Tooltip({ label, placement = 'bottom', delay = 250, disabled, shortcut, content, children }: TooltipProps) { const [open, setOpen] = useState(false) const [coords, setCoords] = useState<{ top: number; left: number } | null>(null) const triggerRef = useRef(null) const tooltipRef = useRef(null) const timerRef = useRef(null) + // When a finger last touched the trigger. A tap makes the browser send a mouseenter + // after it and never the mouseleave, so the tip would open on a tap and stay. + const touchedAtRef = useRef(0) const show = () => { if (disabled || !label) return @@ -60,6 +70,7 @@ export function Tooltip({ label, placement = 'bottom', delay = 250, disabled, sh type TriggerProps = { ref?: React.Ref onMouseEnter?: (e: React.MouseEvent) => void + onTouchStart?: (e: React.TouchEvent) => void onMouseLeave?: (e: React.MouseEvent) => void onFocus?: (e: React.FocusEvent) => void onBlur?: (e: React.FocusEvent) => void @@ -73,7 +84,9 @@ export function Tooltip({ label, placement = 'bottom', delay = 250, disabled, sh if (typeof r === 'function') r(node) else if (r && typeof r === 'object') (r as React.RefObject).current = node }, - onMouseEnter: (e: React.MouseEvent) => { show(); childProps.onMouseEnter?.(e) }, + onTouchStart: (e: React.TouchEvent) => { touchedAtRef.current = Date.now(); hide(); childProps.onTouchStart?.(e) }, + // A touch screen has no hover to hint at: only a real pointer opens the tip. + onMouseEnter: (e: React.MouseEvent) => { if (!touchedRecently(touchedAtRef.current, Date.now())) show(); childProps.onMouseEnter?.(e) }, onMouseLeave: (e: React.MouseEvent) => { hide(); childProps.onMouseLeave?.(e) }, // Keyboard focus only. A dialog hands focus back to the button that opened it // when it closes, and a tooltip over whatever comes next is noise, not help. diff --git a/client/src/mobile/screens/trip/MTripShell.tsx b/client/src/mobile/screens/trip/MTripShell.tsx index 290f6a193..4e2313b37 100644 --- a/client/src/mobile/screens/trip/MTripShell.tsx +++ b/client/src/mobile/screens/trip/MTripShell.tsx @@ -35,6 +35,7 @@ import { edgeFadeClass, useEdgeFade } from '../../components/useEdgeFade' import { useShortcuts } from '../../keyboard/useShortcuts' import { tripCreateIntent } from '../../../components/Layout/useCreateAction' import MDockScrim from '../../components/MDockScrim' +import { setTourHeadSlot } from './tours/tourHeadSlot' /** * Mobile trip screen frame. Owns the chrome the design shares across every @@ -865,8 +866,9 @@ export default function MTripShell({ not in the dock, so nothing was lit up there either, and the screen gave no clue which plugin was open. Same treatment as the others, from the tab entry the planner already builds (id, label, icon). */} - {/* The tours tab on a large screen reads the same way: its own controls sit in its pane. */} - {(trTab.startsWith('plugin:') || trTab === 'tour-planner') && (() => { + {/* The tours tab puts its own controls here instead (tours/tourHeadSlot.ts). */} + {trTab === 'tour-planner' &&
} + {trTab.startsWith('plugin:') && (() => { const tab = planner.TRIP_TABS.find(x => x.id === trTab) if (!tab) return null const Icon = tab.icon diff --git a/client/src/mobile/screens/trip/tours/MTourWorkspace.tsx b/client/src/mobile/screens/trip/tours/MTourWorkspace.tsx index 732ade12b..85357ec4f 100644 --- a/client/src/mobile/screens/trip/tours/MTourWorkspace.tsx +++ b/client/src/mobile/screens/trip/tours/MTourWorkspace.tsx @@ -1,5 +1,6 @@ import { List, Map as MapIcon } from 'lucide-react'; import { useState } from 'react'; +import { createPortal } from 'react-dom'; import TourGpxDropZone from '../../../../components/Tours/TourGpxDropZone'; import TourWorkspaceRail from '../../../../components/Tours/TourWorkspaceRail'; import { TourPlannerToursRail } from '../../../../components/Tours/planner/TourPlannerPanels'; @@ -11,6 +12,7 @@ import { useTripPlannerPageOf } from '../../../../pages/tripPlanner/useTripPlann import MIconBtn from '../../../components/MIconBtn'; import MSegmented from '../../../components/MSegmented'; import type { MTripTabPanelProps } from '../MTripShell'; +import { useTourHeadSlot } from './tourHeadSlot'; /** The pane's two halves: the trip's tours, or the editor with the tour open in it. */ type MTourPane = 'tours' | 'editor'; @@ -64,6 +66,35 @@ export default function MTourWorkspace({ planner }: Pick { + setPane(next); + setMapShown(false); + }; + const head = ( + <> + + className="min-w-0 flex-1" + value={pane} + onChange={pickPane} + options={[ + { value: 'tours', label: t('tours.planner.tripTours') }, + { value: 'editor', label: t(EDITOR_TITLE[mode]) }, + ]} + /> + {!split && ( + setMapShown(!mapShown)} + size={headSlot ? 38 : 36} + className="pointer-events-auto backdrop-blur-[24px] backdrop-saturate-[1.7]" + > + {mapShown ? : } + + )} + + ); return ( @@ -73,22 +104,7 @@ export default function MTourWorkspace({ planner }: Pick -
- - className="min-w-0 flex-1" - value={pane} - onChange={setPane} - options={[ - { value: 'tours', label: t('tours.planner.tripTours') }, - { value: 'editor', label: t(EDITOR_TITLE[mode]) }, - ]} - /> - {!split && ( - setMapShown(true)} size={36}> - - - )} -
+ {!headSlot &&
{head}
}
{pane === 'tours' ? ( @@ -104,6 +120,7 @@ export default function MTourWorkspace({ planner }: Pick ) : ( @@ -132,7 +149,7 @@ export default function MTourWorkspace({ planner }: Pick - {!split && ( + {!split && !headSlot && (
)}
+ {headSlot && createPortal(head, headSlot)} ); } diff --git a/client/src/mobile/screens/trip/tours/tourHeadSlot.ts b/client/src/mobile/screens/trip/tours/tourHeadSlot.ts new file mode 100644 index 000000000..31565bbff --- /dev/null +++ b/client/src/mobile/screens/trip/tours/tourHeadSlot.ts @@ -0,0 +1,34 @@ +/** + * The place in the trip shell's top row that the tours tab fills with its own + * controls: the switch between the trip's tours and the editor, and on a window + * that shows the pane or the map, the map button. The row has the back button + * on one side and nothing else to say on a tablet, so the tab's name made way. + * + * The shell hands the node in through a callback ref; the tab portals into it. + * Kept outside React state so the shell does not render again for it. + */ +import { useSyncExternalStore } from 'react'; + +let slot: HTMLElement | null = null; +const listeners = new Set<() => void>(); + +/** The callback ref of the shell's slot. */ +export function setTourHeadSlot(node: HTMLElement | null): void { + if (node === slot) return; + slot = node; + for (const listener of listeners) listener(); +} + +function subscribe(listener: () => void): () => void { + listeners.add(listener); + return () => listeners.delete(listener); +} + +/** The slot while the shell shows it, else null (the tab then keeps its controls in its pane). */ +export function useTourHeadSlot(): HTMLElement | null { + return useSyncExternalStore( + subscribe, + () => slot, + () => null + ); +} diff --git a/client/src/pages/tripPlanner/b4a-wiring.test.ts b/client/src/pages/tripPlanner/b4a-wiring.test.ts index 98deda047..7098c8f08 100644 --- a/client/src/pages/tripPlanner/b4a-wiring.test.ts +++ b/client/src/pages/tripPlanner/b4a-wiring.test.ts @@ -106,6 +106,9 @@ test('B4A Tours tab is readable, desktop-only off a large screen, and absent wit assert.doesNotMatch(tabs.getText(hook), /\bcan\b|canPlaceEdit|canDayEdit/) assert.match(hookText, /!validTabIds\.includes\(activeTab\)[\s\S]*?setActiveTab\('plan'\)/) assert.match(pageText, /activeTab === 'tour-planner' && enabledAddons\.tours && !isMobile/) + // The app counts as a phone shell on an iPad too: the workspace follows its tab, not the phone test. + assert.equal(initializer(workspace, 'workspaceUp').getText(workspace), "activeTab === 'tour-planner' && (!isMobile || largeTouch)") + assert.doesNotMatch(workspaceText, /!isMobile(?! \|\| largeTouch)/) }) test('B4A selectedTour is derived only from explicit place selection and addon state', () => { diff --git a/client/src/pages/tripPlanner/useTourWorkspace.ts b/client/src/pages/tripPlanner/useTourWorkspace.ts index fbc3f757b..654d957c5 100644 --- a/client/src/pages/tripPlanner/useTourWorkspace.ts +++ b/client/src/pages/tripPlanner/useTourWorkspace.ts @@ -10,6 +10,7 @@ import { useSkiClassification } from '../../components/Tours/ski/useSkiClassific import { useRecordedTrack } from '../../components/Tours/useRecordedTrack'; import { useTourGpxImport } from '../../components/Tours/useTourGpxImport'; import { useWandererBrowser } from '../../components/Tours/wanderer/useWandererBrowser'; +import { useIsWide } from '../../hooks/sizeClass'; import { useAddonStore } from '../../store/addonStore'; import { useTripStore } from '../../store/tripStore'; import { useTourDetailActions } from './useTourDetailActions'; @@ -71,12 +72,17 @@ export function useTourWorkspace(planner: TripPlanner, canPlaceEdit: boolean, ca } = planner; // wanderer only while the admin allows it under Tours (the store reads Tours being on into it too). const wandererAllowed = useAddonStore((state) => state.toursWanderer); + // The workspace is up where its tab is: on a desktop, and in the touch shell on a + // large screen (an iPad, an unfolded foldable). The app counts as a phone shell on + // every device, so the phone test alone left the tablet's editor switched off. + const largeTouch = useIsWide(); + const workspaceUp = activeTab === 'tour-planner' && (!isMobile || largeTouch); const tourPlanner = useTourPlanner({ tripId, canEdit: canPlaceEdit, canAssign: canDayEdit, - active: activeTab === 'tour-planner' && enabledAddons.tours && !isMobile, + active: workspaceUp && enabledAddons.tours, onSaved: async (result) => { upsertTour(result.tour); toast.success(t('tours.planner.saved')); @@ -86,7 +92,7 @@ export function useTourWorkspace(planner: TripPlanner, canPlaceEdit: boolean, ca }); useTourRevisionWatch(tourPlanner, tours); // P2C-03: a save made elsewhere reaches the open editor - usePublishOpenTour(tourPlanner, activeTab === 'tour-planner' && !isMobile); // P6: the chat's "+ Tour" takes a found place into the tour open here + usePublishOpenTour(tourPlanner, workspaceUp); // P6: the chat's "+ Tour" takes a found place into the tour open here const { viewImportedTour, openTourInPlanner } = useTourOpeners(tourPlanner, places, tours); // The tours workspace's GPX import, shared by its button and its file drop. One new @@ -107,7 +113,7 @@ export function useTourWorkspace(planner: TripPlanner, canPlaceEdit: boolean, ca // Browsing the user's wanderer trails in place of the editor rail; the trail shows on the map. const wandererBrowser = useWandererBrowser({ tripId, - enabled: activeTab === 'tour-planner' && wandererAllowed && !isMobile && canPlaceEdit, + enabled: workspaceUp && wandererAllowed && canPlaceEdit, onImported: async (tour) => { upsertTour(tour); await useTripStore.getState().refreshPlaces(tripId); @@ -152,7 +158,7 @@ export function useTourWorkspace(planner: TripPlanner, canPlaceEdit: boolean, ca tours, tripMembers, canEdit: canPlaceEdit, - active: activeTab === 'tour-planner' && enabledAddons.tours && !isMobile, + active: workspaceUp && enabledAddons.tours, trackPaddlePlan, onSaved: takeInSavedTour, }); diff --git a/client/tests/unit/mobile/trip/MTourWorkspace.test.tsx b/client/tests/unit/mobile/trip/MTourWorkspace.test.tsx index 4cacb56a8..73185d266 100644 --- a/client/tests/unit/mobile/trip/MTourWorkspace.test.tsx +++ b/client/tests/unit/mobile/trip/MTourWorkspace.test.tsx @@ -2,6 +2,7 @@ import { fireEvent } from '@testing-library/react'; import type { ReactNode } from 'react'; import { beforeEach, describe, expect, it, vi } from 'vitest'; import MTourWorkspace from '../../../../src/mobile/screens/trip/tours/MTourWorkspace'; +import { setTourHeadSlot } from '../../../../src/mobile/screens/trip/tours/tourHeadSlot'; import { buildPlanner } from '../../../helpers/mobileTrip'; import { render, screen } from '../../../helpers/render'; import { setSizeClass } from '../../../helpers/sizeClass'; @@ -58,6 +59,7 @@ beforeEach(() => { page.wandererOpen = false; page.calls = []; dragBridge.mockClear(); + setTourHeadSlot(null); }); describe('MTourWorkspace', () => { @@ -135,4 +137,24 @@ describe('MTourWorkspace', () => { render(); expect(screen.getByTestId('gpx-drop')).toContainElement(screen.getByTestId('tour-map')); }); + it("FE-MOB-TOURWS-008: with the shell's slot the switch and the map button sit in its top row, and the switch brings the pane back", async () => { + setSizeClass('wide'); + const slot = document.createElement('div'); + document.body.appendChild(slot); + setTourHeadSlot(slot); + render(); + expect(await screen.findByTestId('tour-list')).toBeInTheDocument(); + expect(slot).toContainElement(screen.getByRole('tab', { name: 'tours.planner.tripTours' })); + expect(slot).toContainElement(screen.getByRole('button', { name: 'mobileTrip.mapView' })); + + fireEvent.click(screen.getByRole('button', { name: 'mobileTrip.mapView' })); + expect(screen.getByTestId('tour-map')).toBeInTheDocument(); + // Only the top row's button leads back: the map keeps its corner free. + expect(screen.getAllByRole('button', { name: 'mobileTrip.listView' })).toHaveLength(1); + + fireEvent.click(screen.getByRole('tab', { name: 'tours.planner.title' })); + expect(await screen.findByTestId('tour-editor')).toBeInTheDocument(); + expect(screen.queryByTestId('tour-map')).not.toBeInTheDocument(); + slot.remove(); + }); });