diff --git a/client/scripts/size-baseline.json b/client/scripts/size-baseline.json index d5cf76cf4..6dd3e7959 100644 --- a/client/scripts/size-baseline.json +++ b/client/scripts/size-baseline.json @@ -20,7 +20,7 @@ "src/pages/JourneyDetailPage.test.tsx": 4028, "src/pages/LoginPage.tsx": 1347, "src/pages/TripPlannerPage.tsx": 1128, - "src/pages/atlas/useAtlas.ts": 1210, + "src/pages/atlas/useAtlas.ts": 1207, "src/pages/tripPlanner/useTripPlanner.roadtrip.test.tsx": 3518, "src/pages/tripPlanner/useTripPlanner.test.tsx": 3270, "src/styles/studio.css": 1918 diff --git a/client/scripts/theme-baseline.json b/client/scripts/theme-baseline.json index ced157b71..d16268694 100644 --- a/client/scripts/theme-baseline.json +++ b/client/scripts/theme-baseline.json @@ -183,7 +183,7 @@ "mobile/screens/collections/MCollTripPickerSheet.tsx": 4, "mobile/screens/collections/MCollections.tsx": 14, "mobile/screens/dashboard/MDashWidgets.tsx": 22, - "mobile/screens/dashboard/MDashboard.tsx": 31, + "mobile/screens/dashboard/MDashboard.tsx": 30, "mobile/screens/dashboard/MNewTripSheet.tsx": 12, "mobile/screens/dashboard/MUserMenu.tsx": 7, "mobile/screens/journey/MJourney.tsx": 10, diff --git a/client/src/components/Journey/JourneyMap.test.tsx b/client/src/components/Journey/JourneyMap.test.tsx index 9c9d27cea..be395a70f 100644 --- a/client/src/components/Journey/JourneyMap.test.tsx +++ b/client/src/components/Journey/JourneyMap.test.tsx @@ -1,4 +1,4 @@ -// FE-COMP-JOURNEYMAP-001 to FE-COMP-JOURNEYMAP-062 +// FE-COMP-JOURNEYMAP-001 to FE-COMP-JOURNEYMAP-063 vi.mock('../../api/websocket', () => ({ connect: vi.fn(), @@ -592,6 +592,28 @@ describe('JourneyMap', () => { } }); + it('FE-COMP-JOURNEYMAP-063: paddingStart keeps the journey clear of a rail on the leading side, either way round', () => { + const origRAF = globalThis.requestAnimationFrame; + globalThis.requestAnimationFrame = (cb: FrameRequestCallback) => { cb(0); return 0; }; + try { + const { unmount } = render(); + expect(mockedMap().fitBounds).toHaveBeenLastCalledWith( + expect.anything(), + expect.objectContaining({ paddingTopLeft: [150, 50], paddingBottomRight: [50, 200] }), + ); + unmount(); + document.documentElement.dir = 'rtl'; + render(); + expect(mockedMap().fitBounds).toHaveBeenLastCalledWith( + expect.anything(), + expect.objectContaining({ paddingTopLeft: [50, 50], paddingBottomRight: [150, 200] }), + ); + } finally { + document.documentElement.dir = ''; + globalThis.requestAnimationFrame = origRAF; + } + }); + it('FE-COMP-JOURNEYMAP-026: dark mode picks the dark basemap', async () => { render(); // The default basemap is a vector style now, so it arrives as a style option diff --git a/client/src/components/Journey/JourneyMap.tsx b/client/src/components/Journey/JourneyMap.tsx index c3178c79b..3a111f270 100644 --- a/client/src/components/Journey/JourneyMap.tsx +++ b/client/src/components/Journey/JourneyMap.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useImperativeHandle, useCallback, type CSSProperties, type Ref, type RefObject } from 'react' +import { useEffect, useLayoutEffect, useRef, useImperativeHandle, useCallback, type CSSProperties, type Ref, type RefObject } from 'react' import { clusterPhotos, photoMarkerHtml, type MapPhoto } from './journeyPhotoLayer' import L from 'leaflet' import { useSettingsStore } from '../../store/settingsStore' @@ -76,6 +76,12 @@ interface Props { */ onMarkerCardClick?: (entryId: string) => void paddingBottom?: number + /** + * How much of the map's leading edge a bar laid over it covers (the touch + * shell's rail), in px: framing keeps the journey clear of it. Read when the + * map frames, so a change alone does not rebuild the map. + */ + paddingStart?: number /** CARTO key from the share payload: the public journey has no settings store to read. */ cartoApiKey?: string /** @@ -281,13 +287,23 @@ function markCoords(marks: JourneyMapMark[] | undefined): L.LatLngTuple[] { return (marks ?? []).map(mark => [mark.lat, mark.lng] as L.LatLngTuple) } -function fitOptions(paddingBottom: number | undefined): L.FitBoundsOptions { - return { paddingTopLeft: [50, 50], paddingBottomRight: [50, paddingBottom || 50], maxZoom: 16 } +function fitOptions(paddingBottom: number | undefined, paddingStart = 0): L.FitBoundsOptions { + const rtl = typeof document !== 'undefined' && document.documentElement.dir === 'rtl' + return { + paddingTopLeft: [50 + (rtl ? 0 : paddingStart), 50], + paddingBottomRight: [50 + (rtl ? paddingStart : 0), paddingBottom || 50], + maxZoom: 16, + } } function JourneyMap( - { entries, photos, onPhotoClick, trail, tracks, height = 220, dark, activeMarkerId, onMarkerClick, fullScreen, paddingBottom, cartoApiKey, onMarkerCardClick, layerVisibility = EVERY_LAYER, marks, onMarksPick, plannedEntryIds = NO_PLANNED, ref }: Props, + { entries, photos, onPhotoClick, trail, tracks, height = 220, dark, activeMarkerId, onMarkerClick, fullScreen, paddingBottom, paddingStart = 0, cartoApiKey, onMarkerCardClick, layerVisibility = EVERY_LAYER, marks, onMarksPick, plannedEntryIds = NO_PLANNED, ref }: Props, ) { + // The leading inset is read when the map frames, not a reason to rebuild it. + const paddingStartRef = useRef(paddingStart) + useLayoutEffect(() => { + paddingStartRef.current = paddingStart + }) // Read through a ref: the handler is fixed per surface, and putting it in the // marker effect's deps would rebuild every marker for nothing. const onMarkerCardClickRef = useRef(onMarkerCardClick) @@ -536,7 +552,7 @@ function JourneyMap( const pointCoords = [...allCoords, ...markCoords(marksRef.current)] const fitCoords = pointCoords.length > 0 ? pointCoords : trackCoords marksFramedRef.current = (marksRef.current?.length ?? 0) > 0 - if (fitCoords.length > 0) map.fitBounds(L.latLngBounds(fitCoords), fitOptions(paddingBottom)) + if (fitCoords.length > 0) map.fitBounds(L.latLngBounds(fitCoords), fitOptions(paddingBottom, paddingStartRef.current)) else map.setView([30, 0], 2) } catch {} }) @@ -652,7 +668,7 @@ function JourneyMap( const coords = markCoords(marks) if (!marksFramedRef.current && coords.length > 0) { marksFramedRef.current = true - if (!readerMovedRef.current) map.fitBounds(L.latLngBounds([...entryCoordsRef.current, ...coords]), fitOptions(paddingBottom)) + if (!readerMovedRef.current) map.fitBounds(L.latLngBounds([...entryCoordsRef.current, ...coords]), fitOptions(paddingBottom, paddingStartRef.current)) } draw() diff --git a/client/src/components/Journey/JourneyMapAuto.tsx b/client/src/components/Journey/JourneyMapAuto.tsx index 723f2b6cf..dff1adaf7 100644 --- a/client/src/components/Journey/JourneyMapAuto.tsx +++ b/client/src/components/Journey/JourneyMapAuto.tsx @@ -39,6 +39,12 @@ interface Props { onMarkerClick?: (id: string, type?: string) => void fullScreen?: boolean paddingBottom?: number + /** + * How much of the map's leading edge a bar laid over it covers (the touch + * shell's rail), in px: framing keeps the journey clear of it. Read when the + * map frames, so a change alone does not rebuild the map. + */ + paddingStart?: number /** Open the entry a marker card names when the card is tapped, both renderers. */ onMarkerCardClick?: (entryId: string) => void /** Open an entry's photos from the marker card's thumbnail strip. GL renderer only. */ diff --git a/client/src/components/Journey/JourneyMapGL.test.tsx b/client/src/components/Journey/JourneyMapGL.test.tsx index a9534ec4b..9b7e22ad3 100644 --- a/client/src/components/Journey/JourneyMapGL.test.tsx +++ b/client/src/components/Journey/JourneyMapGL.test.tsx @@ -317,6 +317,14 @@ describe('JourneyMapGL', () => { expect(gl.map.addLayer).toHaveBeenCalledWith(expect.objectContaining({ id: 'journey-route-line' })) }) + it('FE-COMP-JMAPGL-049: paddingStart widens the fit on the side of the rail', () => { + withToken() + render() + expect(gl.map.fitBounds).toHaveBeenCalledWith(gl.boundsList[0], expect.objectContaining({ + padding: { top: 50, bottom: 200, left: 150, right: 50 }, + })) + }) + it('FE-COMP-JMAPGL-010: the camera fits entries and trail with the requested bottom padding', () => { withToken() render( diff --git a/client/src/components/Journey/JourneyMapGL.tsx b/client/src/components/Journey/JourneyMapGL.tsx index 7d03ef8b7..fab59cdeb 100644 --- a/client/src/components/Journey/JourneyMapGL.tsx +++ b/client/src/components/Journey/JourneyMapGL.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useImperativeHandle, useCallback, type Ref } from 'react' +import { useEffect, useLayoutEffect, useRef, useImperativeHandle, useCallback, type Ref } from 'react' import type mapboxgl from 'mapbox-gl' import { useSettingsStore } from '../../store/settingsStore' import { isStandardFamily, supportsCustom3d, wantsTerrain, addCustom3dBuildings, addTerrainAndSky } from '../Map/mapboxSetup' @@ -57,6 +57,12 @@ interface Props { photos?: MapPhoto[] onPhotoClick?: (photoIds: string[]) => void paddingBottom?: number + /** + * How much of the map's leading edge a bar laid over it covers (the touch + * shell's rail), in px: framing keeps the journey clear of it. Read when the + * map frames, so a change alone does not rebuild the map. + */ + paddingStart?: number /** See the Leaflet twin (JRN-04): hidden layers go off the map in place. */ layerVisibility?: JourneyMapLayerVisibility marks?: JourneyMapMark[] @@ -185,9 +191,10 @@ function markBounds(gl: Props['gl'], marks: JourneyMapMark[], points: [number, n return bounds } -function fitOptions(paddingBottom: number | undefined, tilted: boolean | undefined) { +function fitOptions(paddingBottom: number | undefined, tilted: boolean | undefined, paddingStart = 0) { + const rtl = typeof document !== 'undefined' && document.documentElement.dir === 'rtl' return { - padding: { top: 50, bottom: paddingBottom || 50, left: 50, right: 50 }, + padding: { top: 50, bottom: paddingBottom || 50, left: 50 + (rtl ? 0 : paddingStart), right: 50 + (rtl ? paddingStart : 0) }, maxZoom: 16, pitch: tilted ? 45 : 0, duration: 0, @@ -195,8 +202,13 @@ function fitOptions(paddingBottom: number | undefined, tilted: boolean | undefin } function JourneyMapGL( - { entries, trail, tracks, height = 220, dark, activeMarkerId, onMarkerClick, fullScreen, paddingBottom, glProvider = 'mapbox-gl', gl, onMarkerCardClick, onMarkerPhotoClick, photos, onPhotoClick, layerVisibility = EVERY_LAYER, marks, onMarksPick, plannedEntryIds = NO_PLANNED, ref }: Props, + { entries, trail, tracks, height = 220, dark, activeMarkerId, onMarkerClick, fullScreen, paddingBottom, paddingStart = 0, glProvider = 'mapbox-gl', gl, onMarkerCardClick, onMarkerPhotoClick, photos, onPhotoClick, layerVisibility = EVERY_LAYER, marks, onMarksPick, plannedEntryIds = NO_PLANNED, ref }: Props, ) { + // The leading inset is read when the map frames, not a reason to rebuild it. + const paddingStartRef = useRef(paddingStart) + useLayoutEffect(() => { + paddingStartRef.current = paddingStart + }) const onMarkerCardClickRef = useRef(onMarkerCardClick) onMarkerCardClickRef.current = onMarkerCardClick const onMarkerPhotoClickRef = useRef(onMarkerPhotoClick) @@ -526,7 +538,7 @@ function JourneyMapGL( known.forEach(mark => bounds.extend([mark.lng, mark.lat])) if (hasPoints || known.length > 0) { try { - map.fitBounds(bounds, fitOptions(paddingBottom, enableMapbox3d && fullScreen)) + map.fitBounds(bounds, fitOptions(paddingBottom, enableMapbox3d && fullScreen, paddingStartRef.current)) } catch { /* empty bounds */ } } }) @@ -631,7 +643,7 @@ function JourneyMapGL( marksFramedRef.current = true if (!readerMovedRef.current) { try { - map.fitBounds(markBounds(gl, marks, entryPointsRef.current), fitOptions(paddingBottom, enableMapbox3d && fullScreen)) + map.fitBounds(markBounds(gl, marks, entryPointsRef.current), fitOptions(paddingBottom, enableMapbox3d && fullScreen, paddingStartRef.current)) } catch { /* empty bounds */ } } } diff --git a/client/src/mobile/components/MBottomNav.tsx b/client/src/mobile/components/MBottomNav.tsx index 8bffce172..3471cad34 100644 --- a/client/src/mobile/components/MBottomNav.tsx +++ b/client/src/mobile/components/MBottomNav.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from 'react' -import { useNavigate, useLocation } from 'react-router' +import { useNavigate, useLocation, matchPath } from 'react-router' import { useSettingsStore } from '../../store/settingsStore' import { useTranslation } from '../../i18n' import { ChevronRight, MoreHorizontal, Plus, Search, Sparkles, Upload } from 'lucide-react' @@ -9,6 +9,7 @@ import { useNavItems, splitMobileNav } from '../../components/Layout/navItems' import { isNavItemActive, useCreateAction } from '../../components/Layout/useCreateAction' import MFab from './MFab' import { useAssistantHomeLauncher } from '../../components/Assistant/useAssistantHome' +import MDockScrim from './MDockScrim' interface NavItem { to: string; label: string; icon: LucideIcon } @@ -72,6 +73,14 @@ export default function MBottomNav() { `flex h-[42px] w-[42px] flex-none items-center justify-center rounded-full ${ active ? 'bg-m-act text-m-actfg' : 'text-m-muted' }` + // More stands for whichever of its screens is on show, so it is marked as a + // ring: a filled circle beside the filled "+" read as two of the same action. + const moreCls = (active: boolean) => + `flex h-[42px] w-[42px] flex-none items-center justify-center rounded-full ${ + active ? 'bg-[color:var(--m-ic)] text-m-ink ring-[1.5px] ring-inset ring-[color:var(--m-act)]' : 'text-m-muted' + }` + // A map runs to the screen's edge on purpose; everything else fades out under the dock. + const overMap = location.pathname.startsWith('/atlas') || matchPath('/journey/:id', location.pathname) !== null const renderItem = ({ to, label, icon: Icon }: NavItem) => { const active = isActive(to) @@ -120,7 +129,8 @@ export default function MBottomNav() { )} -