From 3fb10c4172686c456c8e9aa21ef8adfdafdf951d Mon Sep 17 00:00:00 2001 From: rathi Date: Wed, 11 Dec 2024 17:45:56 -0500 Subject: [PATCH] hide sidebar component --- .../layout/DashboardLayout/index.tsx | 72 +++++++++++++------ src/components/layout/Sidebar/index.tsx | 41 +++++++++-- src/hooks/useSidebar.ts | 10 +++ 3 files changed, 96 insertions(+), 27 deletions(-) create mode 100644 src/hooks/useSidebar.ts diff --git a/src/components/layout/DashboardLayout/index.tsx b/src/components/layout/DashboardLayout/index.tsx index 3cf3294..c391afe 100644 --- a/src/components/layout/DashboardLayout/index.tsx +++ b/src/components/layout/DashboardLayout/index.tsx @@ -1,33 +1,65 @@ -import React from 'react'; +import React, { createContext, useContext, useState } from 'react'; import { Outlet } from 'react-router-dom'; +import { PanelLeft } from 'lucide-react'; import { Header } from '../Header/index'; import { Sidebar } from '../Sidebar/index'; +import { cn } from '../../../lib/utils'; + +type SidebarContextType = { + isHidden: boolean; + setIsHidden: (hidden: boolean) => void; +}; + +export const SidebarContext = createContext({ + isHidden: false, + setIsHidden: () => {}, +}); + +export const useSidebar = () => useContext(SidebarContext); const DashboardLayout = () => { + const [isHidden, setIsHidden] = useState(false); + return ( -
- {/* Fixed header */} -
-
-
- - {/* Sidebar and main content */} -
- {/* Fixed sidebar */} -
- + +
+ {/* Fixed header */} +
+
- {/* Main content area */} -
-
-
- -
-
+ {/* Sidebar and main content */} +
+ {/* Fixed sidebar */} +
+ +
+ + {/* Main content area */} +
+
+
+ +
+
+
+ + {/* Fixed Show Sidebar Button - Only visible when sidebar is hidden */} + {isHidden && ( + + )}
-
+
); }; diff --git a/src/components/layout/Sidebar/index.tsx b/src/components/layout/Sidebar/index.tsx index 3dfe29d..bb698bc 100644 --- a/src/components/layout/Sidebar/index.tsx +++ b/src/components/layout/Sidebar/index.tsx @@ -4,10 +4,13 @@ import { Settings, MessageSquare, Upload, - History + History, + PanelLeftClose, + PanelLeft } from 'lucide-react'; import { cn } from '../../../lib/utils'; import { useLatestChat } from '../../../hooks/useLatestChat'; +import { useSidebar } from '../../../hooks/useSidebar'; const sidebarItems = [ { @@ -35,6 +38,7 @@ const sidebarItems = [ const Sidebar = () => { const location = useLocation(); const { navigateToChat } = useLatestChat(); + const { isHidden, setIsHidden } = useSidebar(); const isActive = (path: string) => { if (path.startsWith('/dashboard/ask')) { @@ -44,8 +48,13 @@ const Sidebar = () => { }; return ( -
-
+
+
{/* Navigation Links */} + + {/* Toggle Button */} +
); diff --git a/src/hooks/useSidebar.ts b/src/hooks/useSidebar.ts new file mode 100644 index 0000000..6cf102d --- /dev/null +++ b/src/hooks/useSidebar.ts @@ -0,0 +1,10 @@ +import { useContext } from 'react'; +import { SidebarContext } from '../components/layout/DashboardLayout'; + +export const useSidebar = () => { + const context = useContext(SidebarContext); + if (!context) { + throw new Error('useSidebar must be used within a SidebarProvider'); + } + return context; +};