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
25 changes: 23 additions & 2 deletions apps/web/app/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
'use client';

import { useEffect, useState } from 'react';
import { AppSidebar } from '@/components/app-sidebar';
import { SidebarInset, SidebarProvider } from '@/components/ui/sidebar';
import {
SIDEBAR_COOKIE_NAME,
SidebarInset,
SidebarProvider,
} from '@/components/ui/sidebar';
import { Spinner } from '@/components/ui/spinner';
import { useAuth } from '@/lib/auth-context';

Expand All @@ -11,6 +16,22 @@ export default function DashboardLayout({
children: React.ReactNode;
}) {
const { isLoading } = useAuth();
const [sidebarOpen, setSidebarOpen] = useState(true);

useEffect(() => {
const cookies = document.cookie.split('; ').reduce(
(acc, cookie) => {
const [key, value] = cookie.split('=');
acc[key] = value;
return acc;
},
{} as Record<string, string>,
);
const savedState = cookies[SIDEBAR_COOKIE_NAME];
if (savedState !== undefined) {
setSidebarOpen(savedState === 'true');
}
}, []);

if (isLoading) {
return (
Expand All @@ -21,7 +42,7 @@ export default function DashboardLayout({
}

return (
<SidebarProvider>
<SidebarProvider open={sidebarOpen} onOpenChange={setSidebarOpen}>
<AppSidebar />
<SidebarInset className="flex min-h-svh flex-col overflow-hidden">
{children}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/components/ui/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { useIsMobile } from '@/hooks/use-mobile';
import { cn } from '@/lib/utils';

const SIDEBAR_COOKIE_NAME = 'sidebar_state';
export const SIDEBAR_COOKIE_NAME = 'sidebar_state';
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
const SIDEBAR_WIDTH = '16rem';
const SIDEBAR_WIDTH_MOBILE = '18rem';
Expand Down Expand Up @@ -229,7 +229,7 @@ function Sidebar({
data-slot="sidebar-container"
data-side={side}
className={cn(
'fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear data-[side=left]:left-0 data-[side=left]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)] data-[side=right]:right-0 data-[side=right]:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)] md:flex',
'fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear data-[side=left]:left-0 data-[side=left]:group-data-[collapsible=offcanvas]:-left-(--sidebar-width) data-[side=right]:right-0 data-[side=right]:group-data-[collapsible=offcanvas]:-right-(--sidebar-width) md:flex',
// Adjust the padding for floating and inset variants.
variant === 'floating' || variant === 'inset'
? 'p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]'
Expand Down
Loading