mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-20 23:21:06 +02:00
feat(layout-shell): implement local storage for playground sidebar state management
This commit is contained in:
parent
78594d5248
commit
6d0e151b5f
1 changed files with 21 additions and 2 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import { useAtomValue } from "jotai";
|
||||
import dynamic from "next/dynamic";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { activeTabAtom, type Tab } from "@/atoms/tabs/tabs.atom";
|
||||
import { Logo } from "@/components/Logo";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
|
|
@ -41,6 +41,8 @@ const DocumentTabContent = dynamic(
|
|||
}
|
||||
);
|
||||
|
||||
const PLAYGROUND_SIDEBAR_COLLAPSED_STORAGE_KEY = "surfsense:layout:v1:playground-sidebar-collapsed";
|
||||
|
||||
function MacDesktopTitleBar({
|
||||
isSidebarCollapsed,
|
||||
onToggleSidebar,
|
||||
|
|
@ -232,8 +234,25 @@ export function LayoutShell({
|
|||
() => ({ isCollapsed, setIsCollapsed, toggleCollapsed }),
|
||||
[isCollapsed, setIsCollapsed, toggleCollapsed]
|
||||
);
|
||||
useEffect(() => {
|
||||
try {
|
||||
setIsPlaygroundSidebarCollapsed(
|
||||
window.localStorage.getItem(PLAYGROUND_SIDEBAR_COLLAPSED_STORAGE_KEY) === "true"
|
||||
);
|
||||
} catch {}
|
||||
}, []);
|
||||
|
||||
const handlePlaygroundSidebarToggle = () => {
|
||||
setIsPlaygroundSidebarCollapsed((collapsed) => !collapsed);
|
||||
setIsPlaygroundSidebarCollapsed((collapsed) => {
|
||||
const nextCollapsed = !collapsed;
|
||||
try {
|
||||
window.localStorage.setItem(
|
||||
PLAYGROUND_SIDEBAR_COLLAPSED_STORAGE_KEY,
|
||||
String(nextCollapsed)
|
||||
);
|
||||
} catch {}
|
||||
return nextCollapsed;
|
||||
});
|
||||
};
|
||||
|
||||
// Mobile layout
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue