mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 03:50:30 +00:00
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.
This commit is contained in:
@@ -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<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];
|
||||
}
|
||||
Reference in New Issue
Block a user