Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions web_src/src/ui/CanvasPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { CustomEdge } from "./CustomEdge";
import { Header, type BreadcrumbItem } from "./Header";
import { Simulation } from "./storybooks/useSimulation";
import { CanvasPageState, useCanvasState } from "./useCanvasState";
import { useMinimapVisibility } from "./useMinimapVisibility";
import { SidebarEvent } from "../componentSidebar/types";
import { CanvasLogSidebar, type LogEntry, type LogScopeFilter, type LogTypeFilter } from "../CanvasLogSidebar";

Expand Down Expand Up @@ -1526,7 +1527,7 @@ function CanvasContent({
const [expandedRuns, setExpandedRuns] = useState<Set<string>>(() => new Set());
const [logSidebarHeight, setLogSidebarHeight] = useState(320);
const [isSnapToGridEnabled, setIsSnapToGridEnabled] = useState(true);
const [isMinimapVisible, setIsMinimapVisible] = useState(true);
const { isMinimapVisible, setIsMinimapVisible } = useMinimapVisibility(false);

useEffect(() => {
const activeNoteId = getActiveNoteId();
Expand Down Expand Up @@ -2207,7 +2208,7 @@ function CanvasContent({
? "bg-emerald-50 text-emerald-700 hover:bg-emerald-100"
: "text-slate-600 hover:text-slate-900"
}`}
onClick={() => setIsMinimapVisible((prev) => !prev)}
onClick={() => setIsMinimapVisible((prev: boolean) => !prev)}
aria-pressed={isMinimapVisible}
>
<MapIcon className="h-3 w-3" />
Expand Down
33 changes: 33 additions & 0 deletions web_src/src/ui/CanvasPage/useMinimapVisibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useEffect, useState } from "react";

const CANVAS_MINIMAP_VISIBLE_STORAGE_KEY = "canvasMinimapVisible";

export function useMinimapVisibility(defaultValue = false) {
const [isMinimapVisible, setIsMinimapVisible] = useState(() => {
if (typeof window === "undefined") {
return defaultValue;
}

const storedMinimapState = window.localStorage.getItem(CANVAS_MINIMAP_VISIBLE_STORAGE_KEY);
if (storedMinimapState === null) {
return defaultValue;
}

try {
return JSON.parse(storedMinimapState);
} catch (error) {
console.warn("Failed to parse minimap visibility state:", error);
return defaultValue;
}
});

useEffect(() => {
if (typeof window === "undefined") {
return;
}

window.localStorage.setItem(CANVAS_MINIMAP_VISIBLE_STORAGE_KEY, JSON.stringify(isMinimapVisible));
}, [isMinimapVisible]);

return { isMinimapVisible, setIsMinimapVisible };
}