mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
b65a1bb65c
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.
31 lines
869 B
TypeScript
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];
|
|
}
|