Store sidebar state

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-09-08 17:03:40 +02:00
parent 541f851231
commit 5462ae6239

View File

@@ -10,8 +10,23 @@ import { Button } from "../Button/Button";
const sidebarContext = createContext({ open: true });
function useSidebarState() {
const [open, setOpenState] = useState(() => {
const stored = localStorage.getItem("sidebar-open");
return stored !== null ? JSON.parse(stored) : true;
});
const setOpen = (value: boolean) => {
setOpenState(value);
localStorage.setItem("sidebar-open", JSON.stringify(value));
};
return [open, setOpen] as const;
}
export function Sidebar({ children }: PropsWithChildren) {
const [open, setOpen] = useState(true);
const [open, setOpen] = useSidebarState();
return (
<sidebarContext.Provider value={{ open }}>
<aside