diff --git a/client/src/components/Collections/CollectionMap.tsx b/client/src/components/Collections/CollectionMap.tsx index 7a5d6e201..f912e1792 100644 --- a/client/src/components/Collections/CollectionMap.tsx +++ b/client/src/components/Collections/CollectionMap.tsx @@ -15,6 +15,9 @@ interface CollectionMapProps { dark: boolean /** A control bar floats over the top of the map (the desktop panel's), so the frame starts below it. */ underBar?: boolean + /** Given, the padlock sits on the map: locked, picking a place leaves the camera where it is (#2010). */ + locked?: boolean + onToggleLock?: () => void } /** How far a pin reaches from its point: half a selected pin (44 px) and the rating badge on its corner. */ @@ -69,7 +72,7 @@ function framePoints(places: CollectionPlace[]): [number, number][] { * box instead, clear of the edges and of the controls floating over it, and lands * while the map is built rather than flying in. */ -export default function CollectionMap({ places, selectedPlaceId, onOpenPlace, onDeselect, dark, underBar = false }: CollectionMapProps): React.ReactElement { +export default function CollectionMap({ places, selectedPlaceId, onOpenPlace, onDeselect, dark, underBar = false, locked = false, onToggleLock }: CollectionMapProps): React.ReactElement { const pts = useMemo(() => mappablePlaces(places).map(withMarkerCategory), [places]) const tileUrl = useTileUrl(dark ? OFM_DARK : OFM_POSITRON) const focusPoints = useMemo(() => framePoints(pts), [pts]) @@ -95,6 +98,8 @@ export default function CollectionMap({ places, selectedPlaceId, onOpenPlace, on focusPoints={focusPoints} focusKey={focusKey} fitPadding={framePadding(underBar)} + followSelection={!locked} + onToggleFollow={onToggleLock} /> ) diff --git a/client/src/components/Collections/CollectionMapPanel.tsx b/client/src/components/Collections/CollectionMapPanel.tsx index a3ec7214a..146e7d13f 100644 --- a/client/src/components/Collections/CollectionMapPanel.tsx +++ b/client/src/components/Collections/CollectionMapPanel.tsx @@ -28,6 +28,9 @@ interface CollectionMapPanelProps { onLabelFilter?: (ids: number[]) => void canManageLabels?: boolean onManageLabels?: () => void + /** The padlock on the desktop map (#2010); the phone has no hover to look around with. */ + mapLocked?: boolean + onToggleMapLocked?: () => void t: TranslationFn } @@ -39,7 +42,7 @@ interface CollectionMapPanelProps { export default function CollectionMapPanel({ places, selectedPlaceId, onSelect, onDeselect, dark, overlay, view, onToggleView, search, onSearch, labelOptions = [], labelFilter = [], onLabelFilter, canManageLabels = false, - onManageLabels, t, + onManageLabels, mapLocked = false, onToggleMapLocked, t, }: CollectionMapPanelProps): React.ReactElement { const showLabels = onLabelFilter != null && (labelOptions.length > 0 || canManageLabels) return ( @@ -51,6 +54,8 @@ export default function CollectionMapPanel({ onDeselect={onDeselect} dark={dark} underBar={overlay} + locked={overlay && mapLocked} + onToggleLock={overlay ? onToggleMapLocked : undefined} /> {overlay && (
diff --git a/client/src/hooks/useMapLock.ts b/client/src/hooks/useMapLock.ts new file mode 100644 index 000000000..77f973c2b --- /dev/null +++ b/client/src/hooks/useMapLock.ts @@ -0,0 +1,30 @@ +import { useCallback, useState } from 'react'; + +const MAP_LOCK_KEY = 'trek:map-locked'; + +/** + * Whether a map keeps its camera when a place or a day is picked (#2010). One + * setting per browser for every map that offers the padlock, the trip planner + * and the collections alike: whoever locked one expects the other to hold still too. + */ +export function useMapLock(): [boolean, () => void] { + const [locked, setLocked] = useState(() => { + try { + return localStorage.getItem(MAP_LOCK_KEY) === '1'; + } catch { + return false; + } + }); + const toggle = useCallback(() => { + setLocked((prev) => { + const next = !prev; + try { + localStorage.setItem(MAP_LOCK_KEY, next ? '1' : '0'); + } catch { + /* private mode keeps it for the session */ + } + return next; + }); + }, []); + return [locked, toggle]; +} diff --git a/client/src/pages/CollectionsPage.test.tsx b/client/src/pages/CollectionsPage.test.tsx index 42658d5e4..e191adcd5 100644 --- a/client/src/pages/CollectionsPage.test.tsx +++ b/client/src/pages/CollectionsPage.test.tsx @@ -59,6 +59,10 @@ function makeHook(overrides: Record = {}) { heroHeight: 0, listColRef: { current: null }, listColRect: null, + mapColRef: { current: null }, + mapColRect: null, + mapLocked: false, + toggleMapLocked: vi.fn(), categories: [], collections: [{ id: 1, name: 'Test', is_owner: true }], ownedLists: [{ id: 1, name: 'Test', is_owner: true }], diff --git a/client/src/pages/CollectionsPage.tsx b/client/src/pages/CollectionsPage.tsx index 2d40dcf99..47bb876fd 100644 --- a/client/src/pages/CollectionsPage.tsx +++ b/client/src/pages/CollectionsPage.tsx @@ -73,11 +73,16 @@ function CollectionsPageDesktop(): React.ReactElement { if (c.view !== 'map') c.setSelectedPlaceId(null) c.setView(c.view === 'map' ? 'list' : 'map') } - // Clicking a marker in the full-map view drops back to the split so the list - // + detail come into view alongside the map. - const onMapSelect = (id: number) => { showPlace(id); if (c.view === 'map') c.setView('list') } + // A marker shows its place and the map stays as it is: on the full map the + // detail docks on the map's edge instead of bringing the list back. + const onMapSelect = (id: number) => showPlace(id) const desktopSplit = c.isWide && c.hasMappable + // Where the place detail docks: over the list in the split, on the map's start + // edge when the map has the whole width, and as a centred sheet otherwise. + const detailDock = !desktopSplit ? null + : c.view === 'map' ? (c.mapColRect ? { left: c.mapColRect.left + 12, width: Math.min(420, c.mapColRect.width - 24) } : null) // rtl-lint-disable: a measured viewport position, like the list dock + : c.listColRect const mapShown = c.hasMappable && (c.view === 'map' || c.isWide) const mapOverlay = c.isWide && mapShown // the map carries the toggle + search const canAddPlace = typeof c.activeId === 'number' && c.canEdit // a real list you can edit @@ -112,6 +117,8 @@ function CollectionsPageDesktop(): React.ReactElement { onToggleView={toggleView} search={c.search} onSearch={c.setSearch} + mapLocked={c.mapLocked} + onToggleMapLocked={c.toggleMapLocked} t={t} /> ) @@ -184,7 +191,7 @@ function CollectionsPageDesktop(): React.ReactElement { body = (
{listColumn}
-
{mapPanel(true)}
+
{mapPanel(true)}
) } else if (c.view === 'map' && c.hasMappable) { @@ -343,14 +350,14 @@ function CollectionsPageDesktop(): React.ReactElement { visible + interactive). On the desktop split it docks over the list column so the map stays clear; otherwise it's a full-width sheet. Clicking another place / the map background re-points the selection. */} - {c.selectedPlace && c.view !== 'map' && ( + {c.selectedPlace && (c.view !== 'map' || c.hasMappable) && ( c.updatePlace(c.selectedPlace!.id, patch)} diff --git a/client/src/pages/CollectionsPage.wiring.test.tsx b/client/src/pages/CollectionsPage.wiring.test.tsx index ac7c72266..8bb468ef0 100644 --- a/client/src/pages/CollectionsPage.wiring.test.tsx +++ b/client/src/pages/CollectionsPage.wiring.test.tsx @@ -4,7 +4,7 @@ // to the hook. The page follows the Page pattern, so useCollections is mocked and // each child is stubbed with a prop-driven button. import React from 'react' -import { render, screen, fireEvent } from '../../tests/helpers/render' +import { render, screen, fireEvent, cleanup } from '../../tests/helpers/render' import CollectionsPage from './CollectionsPage' vi.mock('../components/Layout/Navbar', () => ({ default: () =>