Skip to content

Commit fa0f127

Browse files
authored
Merge pull request #1663 from mfts/fix/sidebar-state
fix: sidebar state
2 parents 7691662 + 41f0922 commit fa0f127

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

components/layouts/app.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
import { AppSidebar } from "@/components/sidebar/app-sidebar";
1+
import Cookies from "js-cookie";
22

3-
import { Separator } from "../ui/separator";
4-
import { SidebarInset, SidebarTrigger } from "../ui/sidebar";
5-
import { SidebarProvider } from "../ui/sidebar";
6-
import { AppBreadcrumb } from "./breadcrumb";
7-
import TrialBanner from "./trial-banner";
3+
import { AppBreadcrumb } from "@/components/layouts/breadcrumb";
4+
import TrialBanner from "@/components/layouts/trial-banner";
5+
import { AppSidebar } from "@/components/sidebar/app-sidebar";
6+
import { Separator } from "@/components/ui/separator";
7+
import {
8+
SIDEBAR_COOKIE_NAME,
9+
SidebarInset,
10+
SidebarProvider,
11+
SidebarTrigger,
12+
} from "@/components/ui/sidebar";
813

914
export default function AppLayout({ children }: { children: React.ReactNode }) {
15+
const isSidebarOpen = Cookies.get(SIDEBAR_COOKIE_NAME) === "true";
16+
1017
return (
11-
<SidebarProvider>
18+
<SidebarProvider defaultOpen={isSidebarOpen}>
1219
<div className="flex flex-1 flex-col gap-x-1 bg-gray-50 dark:bg-black md:flex-row">
1320
<AppSidebar />
1421
<SidebarInset className="ring-1 ring-gray-200 dark:ring-gray-800">

components/ui/sidebar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { Slot } from "@radix-ui/react-slot";
44
import { VariantProps, cva } from "class-variance-authority";
55
import { PanelLeft } from "lucide-react";
66

7+
import { useIsMobile } from "@/lib/hooks/use-mobile";
8+
import { cn } from "@/lib/utils";
9+
710
import { Button } from "@/components/ui/button";
811
import { Input } from "@/components/ui/input";
912
import { Separator } from "@/components/ui/separator";
@@ -16,10 +19,7 @@ import {
1619
TooltipTrigger,
1720
} from "@/components/ui/tooltip";
1821

19-
import { useIsMobile } from "@/lib/hooks/use-mobile";
20-
import { cn } from "@/lib/utils";
21-
22-
const SIDEBAR_COOKIE_NAME = "sidebar:state";
22+
export const SIDEBAR_COOKIE_NAME = "sidebar:state";
2323
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
2424
const SIDEBAR_WIDTH = "16rem";
2525
const SIDEBAR_WIDTH_MOBILE = "18rem";

0 commit comments

Comments
 (0)