Fix scan/guide visibility with per-project preferences

- Store showScans/showGuides preferences per project so toggling
  persists when switching between projects
- Apply showGuides/showScans directly on guide and scan renderer groups
- Set projectId in both editor and viewer pages on mount

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Aymeric Rabot
2026-02-27 01:38:10 -05:00
co-authored by Claude Opus 4.6
parent d0e0fe7e1e
commit 31c09bacdd
5 changed files with 58 additions and 5 deletions
+40 -4
View File
@@ -47,6 +47,10 @@ type ViewerState = {
showGuides: boolean
setShowGuides: (show: boolean) => void
projectId: string | null
setProjectId: (id: string | null) => void
projectPreferences: Record<string, { showScans?: boolean, showGuides?: boolean }>
// Smart selection update
setSelection: (updates: Partial<SelectionPath>) => void
resetSelection: () => void
@@ -80,10 +84,43 @@ const useViewer = create<ViewerState>()(
setWallMode: (mode) => set({ wallMode: mode }),
showScans: true,
setShowScans: (show) => set({ showScans: show }),
setShowScans: (show) =>
set((state) => {
const projectPreferences = { ...(state.projectPreferences || {}) };
if (state.projectId) {
projectPreferences[state.projectId] = {
...(projectPreferences[state.projectId] || {}),
showScans: show,
};
}
return { showScans: show, projectPreferences };
}),
showGuides: true,
setShowGuides: (show) => set({ showGuides: show }),
setShowGuides: (show) =>
set((state) => {
const projectPreferences = { ...(state.projectPreferences || {}) };
if (state.projectId) {
projectPreferences[state.projectId] = {
...(projectPreferences[state.projectId] || {}),
showGuides: show,
};
}
return { showGuides: show, projectPreferences };
}),
projectId: null,
setProjectId: (id) =>
set((state) => {
if (!id) return { projectId: id };
const prefs = state.projectPreferences?.[id] || {};
return {
projectId: id,
showScans: prefs.showScans ?? true,
showGuides: prefs.showGuides ?? true,
};
}),
projectPreferences: {},
setSelection: (updates) =>
set((state) => {
@@ -130,8 +167,7 @@ const useViewer = create<ViewerState>()(
cameraMode: state.cameraMode,
levelMode: state.levelMode,
wallMode: state.wallMode,
showScans: state.showScans,
showGuides: state.showGuides,
projectPreferences: state.projectPreferences,
}),
},
),