Files
TREK/client/src/hooks/useMapLock.ts
T
Maurice b65a1bb65c feat(collections): the map's padlock, and a picked place on the full map keeps the map
The collections map gets the trip map's padlock (#2010): locked, a click on a
place leaves the camera where it is, so places can be clicked through without
the map zooming in and out. One setting for both maps. On the full map a
picked place no longer brings the list back: its details dock on the map's
edge, or open as a sheet on a narrow screen.
2026-11-15 12:11:42 +01:00

31 lines
869 B
TypeScript

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<boolean>(() => {
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];
}