Added persistance to sidebar state

This commit is contained in:
Utkarsh-Patel-13 2025-08-08 11:17:43 -07:00
parent 658410d9e2
commit 544c75d6ad
2 changed files with 8 additions and 24 deletions

View file

@ -1,5 +1,6 @@
"use client";
"use server";
import { cookies } from "next/headers";
import type React from "react";
import { DashboardBreadcrumb } from "@/components/dashboard-breadcrumb";
import { AppSidebarProvider } from "@/components/sidebar/AppSidebarProvider";
@ -7,7 +8,7 @@ import { ThemeTogglerComponent } from "@/components/theme/theme-toggle";
import { Separator } from "@/components/ui/separator";
import { SidebarInset, SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar";
export function DashboardClientLayout({
export async function DashboardClientLayout({
children,
searchSpaceId,
navSecondary,
@ -18,8 +19,11 @@ export function DashboardClientLayout({
navSecondary: any[];
navMain: any[];
}) {
const cookieStore = await cookies();
const defaultOpen = cookieStore.get("sidebar_state")?.value === "true";
return (
<SidebarProvider>
<SidebarProvider defaultOpen={defaultOpen}>
{/* Use AppSidebarProvider which fetches user, search space, and recent chats */}
<AppSidebarProvider
searchSpaceId={searchSpaceId}

View file

@ -1,6 +1,6 @@
"use client";
import { AlertCircle, Trash2 } from "lucide-react";
import { Trash2 } from "lucide-react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { AppSidebar } from "@/components/sidebar/app-sidebar";
import { Button } from "@/components/ui/button";
@ -50,26 +50,6 @@ interface AppSidebarProviderProps {
}[];
}
// Loading skeleton component
const LoadingSkeleton = () => (
<div className="space-y-2 p-2">
{Array.from({ length: 3 }).map((_, i) => (
<div key={i} className="h-8 bg-muted animate-pulse rounded-md" />
))}
</div>
);
// Error state component
const ErrorState = ({ error, onRetry }: { error: string; onRetry: () => void }) => (
<div className="p-4 text-center">
<AlertCircle className="h-8 w-8 text-destructive mx-auto mb-2" />
<p className="text-sm text-muted-foreground mb-2">{error}</p>
<Button variant="outline" size="sm" onClick={onRetry}>
Retry
</Button>
</div>
);
export function AppSidebarProvider({
searchSpaceId,
navSecondary,