privatize the setting of desktop mode and fix snapshots

This commit is contained in:
Ryan Di
2025-10-20 11:28:12 +11:00
parent 75c5d1cefc
commit 2a990f580d
4 changed files with 60 additions and 53 deletions

View File

@@ -14,7 +14,7 @@ export type EditorInterface = Readonly<{
}>;
// storage key
export const DESKTOP_UI_MODE_STORAGE_KEY = "excalidraw.desktopUIMode";
const DESKTOP_UI_MODE_STORAGE_KEY = "excalidraw.desktopUIMode";
// breakpoints
// mobile: up to 699px
@@ -185,3 +185,41 @@ export const createUserAgentDescriptor = (
platform,
} as const;
};
export const loadDesktopUIModePreference = () => {
if (typeof window === "undefined") {
return null;
}
try {
const stored = window.localStorage.getItem(DESKTOP_UI_MODE_STORAGE_KEY);
if (stored === "compact" || stored === "full") {
return stored as EditorInterface["desktopUIMode"];
}
} catch (error) {
// ignore storage access issues (e.g., Safari private mode)
}
return null;
};
const persistDesktopUIMode = (mode: EditorInterface["desktopUIMode"]) => {
if (typeof window === "undefined") {
return;
}
try {
window.localStorage.setItem(DESKTOP_UI_MODE_STORAGE_KEY, mode);
} catch (error) {
// ignore storage access issues (e.g., Safari private mode)
}
};
export const setDesktopUIMode = (mode: EditorInterface["desktopUIMode"]) => {
if (mode !== "compact" && mode !== "full") {
return;
}
persistDesktopUIMode(mode);
return mode;
};