fix(mobile): the iPad's tour tab opens saved tours, keeps its switch in the top row, and a tap shows no tooltip

This commit is contained in:
Maurice
2026-11-08 11:43:45 +01:00
parent 4f1f48eec5
commit eafb30555c
10 changed files with 145 additions and 26 deletions
+1
View File
@@ -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.",
@@ -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<void>
/** 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<typeof useTourStageRail
}
export function TourPlannerToursRail({ planner, tours, days, loading, onAssignToDay, onViewGpxTour, onDeleteTour,
gpxImport, onTakenOver, canEdit: editPermission, canAssign: assignPermission }: TourPlannerToursRailProps) {
gpxImport, onTakenOver, canEdit: editPermission, canAssign: assignPermission, floatingHead = false }: TourPlannerToursRailProps) {
const { canEdit, canAssign } = useTourPermissions({ canEdit: editPermission ?? planner.canEdit, canAssign: assignPermission ?? planner.canAssign })
const { t } = useTranslation()
const toast = useToast()
@@ -734,7 +738,7 @@ export function TourPlannerToursRail({ planner, tours, days, loading, onAssignTo
return (
<aside className="flex h-full min-h-0 flex-col" aria-label={t('tours.planner.tripTours')}>
<div className={RAIL_HEAD} style={{ background: NEUTRAL_TINT }}>
<div className={floatingHead ? FLOATING_RAIL_HEAD : RAIL_HEAD} style={{ background: NEUTRAL_TINT }}>
<RailTitle title={t('tours.planner.tripTours')} />
{canEdit && <TourAddMenu planner={planner} gpxImport={gpxImport} onTakenOver={onTakenOver} disabled={isSaving} />}
</div>
@@ -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(<Tooltip label="Add a tour" delay={0}><button>+</button></Tooltip>)
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')
})
})
+14 -1
View File
@@ -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<HTMLElement | null>(null)
const tooltipRef = useRef<HTMLDivElement | null>(null)
const timerRef = useRef<number | null>(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<HTMLElement>
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<HTMLElement | null>).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.
@@ -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' && <div ref={setTourHeadSlot} className="pointer-events-auto absolute inset-x-[52px] top-1/2 flex -translate-y-1/2 items-center gap-2" />}
{trTab.startsWith('plugin:') && (() => {
const tab = planner.TRIP_TABS.find(x => x.id === trTab)
if (!tab) return null
const Icon = tab.icon
@@ -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<MTripTabPanelProps, 'pl
const showPane = split || !mapShown;
const showMap = split || mapShown;
const { t } = planner;
const headSlot = useTourHeadSlot();
// In the shell's top row the switch also brings the pane back from the map.
const pickPane = (next: MTourPane) => {
setPane(next);
setMapShown(false);
};
const head = (
<>
<MSegmented<MTourPane>
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 && (
<MIconBtn
ariaLabel={mapShown ? t('mobileTrip.listView') : t('mobileTrip.mapView')}
onClick={() => setMapShown(!mapShown)}
size={headSlot ? 38 : 36}
className="pointer-events-auto backdrop-blur-[24px] backdrop-saturate-[1.7]"
>
{mapShown ? <List size={17} strokeWidth={2} /> : <MapIcon size={17} strokeWidth={2} />}
</MIconBtn>
)}
</>
);
return (
<TourGpxDropZone gpxImport={tourGpxImport} canEdit={canPlaceEdit} className="absolute inset-0">
@@ -73,22 +104,7 @@ export default function MTourWorkspace({ planner }: Pick<MTripTabPanelProps, 'pl
aria-label={t('tours.planner.tripTours')}
className="flex h-full min-w-0 flex-1 flex-col split:w-[var(--trip-pane-open)] split:flex-none split:border-e split:border-[color:var(--m-rowbr)]"
>
<div className="flex items-center gap-2 px-4 pb-2 pt-1">
<MSegmented<MTourPane>
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 && (
<MIconBtn ariaLabel={t('mobileTrip.mapView')} onClick={() => setMapShown(true)} size={36}>
<MapIcon size={17} strokeWidth={2} />
</MIconBtn>
)}
</div>
{!headSlot && <div className="flex items-center gap-2 px-4 pb-2 pt-1">{head}</div>}
<div className="relative min-h-0 flex-1 overflow-hidden pb-[env(safe-area-inset-bottom,0px)]">
{pane === 'tours' ? (
<LazyPanel id="m-tour-tours">
@@ -104,6 +120,7 @@ export default function MTourWorkspace({ planner }: Pick<MTripTabPanelProps, 'pl
gpxImport={tourGpxImport}
onViewGpxTour={page.viewImportedTour}
onTakenOver={tourDetailActions.onTakenOver}
floatingHead
/>
</LazyPanel>
) : (
@@ -132,7 +149,7 @@ export default function MTourWorkspace({ planner }: Pick<MTripTabPanelProps, 'pl
onViewportChange={wandererBrowser.onViewportChange}
paddleChecklist={page.paddleChecklist}
/>
{!split && (
{!split && !headSlot && (
<div className="absolute start-3 top-3 z-20">
<MIconBtn
ariaLabel={t('mobileTrip.listView')}
@@ -146,6 +163,7 @@ export default function MTourWorkspace({ planner }: Pick<MTripTabPanelProps, 'pl
</div>
)}
</div>
{headSlot && createPortal(head, headSlot)}
</TourGpxDropZone>
);
}
@@ -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
);
}
@@ -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', () => {
@@ -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,
});
@@ -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(<MTourWorkspace planner={buildPlanner()} />);
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(<MTourWorkspace planner={buildPlanner()} />);
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();
});
});