add mouse tool bindings persistence with localStorage
This commit is contained in:
@@ -152,6 +152,10 @@ function App({ container_id, imageStacks, autoCacheStack, annotationJson, viewer
|
||||
const elementRef = useRef<HTMLDivElement>(null)
|
||||
const running = useRef(false)
|
||||
|
||||
|
||||
const MOUSE_SETTINGS_KEY = "dv3d_mouseToolBindings";
|
||||
const CTRL_MOUSE_SETTINGS_KEY = "dv3d_ctrlMouseToolBindings";
|
||||
|
||||
// State to control preset menu open/close
|
||||
const [presetsOpen, setPresetsOpen] = useState(false);
|
||||
|
||||
@@ -176,6 +180,8 @@ function App({ container_id, imageStacks, autoCacheStack, annotationJson, viewer
|
||||
() => Array(MAX_VIEWPORTS).fill([])
|
||||
);
|
||||
|
||||
|
||||
|
||||
// Replace all setViewportImageIds calls with this function:
|
||||
const setViewportImageIds = (value: React.SetStateAction<string[][]>) => {
|
||||
// Log every call
|
||||
@@ -502,6 +508,9 @@ function App({ container_id, imageStacks, autoCacheStack, annotationJson, viewer
|
||||
renderingEngineRef.current.render();
|
||||
return next;
|
||||
});
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
// Add this function to gather and format metadata:
|
||||
@@ -562,7 +571,32 @@ function App({ container_id, imageStacks, autoCacheStack, annotationJson, viewer
|
||||
setMetaModalOpen(true);
|
||||
};
|
||||
|
||||
// Inside your App component:
|
||||
|
||||
// --- Load from localStorage on mount ---
|
||||
useEffect(() => {
|
||||
try {
|
||||
const mouse = localStorage.getItem(MOUSE_SETTINGS_KEY);
|
||||
const ctrl = localStorage.getItem(CTRL_MOUSE_SETTINGS_KEY);
|
||||
if (mouse) setMouseToolBindings(JSON.parse(mouse));
|
||||
if (ctrl) setCtrlMouseToolBindings(JSON.parse(ctrl));
|
||||
} catch (e) {
|
||||
// Ignore parse errors
|
||||
}
|
||||
}, []);
|
||||
|
||||
// --- Save to localStorage when changed ---
|
||||
useEffect(() => {
|
||||
try {
|
||||
localStorage.setItem(MOUSE_SETTINGS_KEY, JSON.stringify(mouseToolBindings));
|
||||
} catch (e) {}
|
||||
}, [mouseToolBindings]);
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
localStorage.setItem(CTRL_MOUSE_SETTINGS_KEY, JSON.stringify(ctrlMouseToolBindings));
|
||||
} catch (e) {}
|
||||
}, [ctrlMouseToolBindings]);
|
||||
|
||||
useEffect(() => {
|
||||
window.loadDicomStackFromFiles = (files: FileList | File[]) => {
|
||||
// Convert FileList to array if needed
|
||||
|
||||
Reference in New Issue
Block a user