From 0c76ed90721c7f09c2bf2036825728b9ee0c71b3 Mon Sep 17 00:00:00 2001 From: ash1shkumar Date: Sat, 6 Jun 2026 00:26:52 +0530 Subject: [PATCH] refactor: centralize sidebar layout state --- frontend/app/components/AppShell.tsx | 35 +++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/frontend/app/components/AppShell.tsx b/frontend/app/components/AppShell.tsx index 25ffafa..98f5a20 100644 --- a/frontend/app/components/AppShell.tsx +++ b/frontend/app/components/AppShell.tsx @@ -1,18 +1,13 @@ "use client"; +import { useMemo } from "react"; import { usePathname } from "next/navigation"; import CommandPalette from "./CommandPalette"; import Sidebar from "./Sidebar"; import TopNavbar from "./TopNavbar"; -export default function AppShell({ - children, -}: { - children: React.ReactNode; -}) { - const pathname = usePathname(); - +function getLayoutState(pathname: string | null) { const isPublicRoute = pathname === "/" || pathname === "/login" || @@ -24,11 +19,35 @@ export default function AppShell({ const hideSidebar = isPublicRoute || isInsightsRoute; - // Insights pages manage their own spacing const mainClass = hideSidebar ? "min-w-0 flex-1 overflow-x-hidden" : "min-w-0 flex-1 overflow-x-hidden p-6"; + return { + isPublicRoute, + isInsightsRoute, + hideSidebar, + mainClass, + }; +} + + +export default function AppShell({ + children, +}: { + children: React.ReactNode; +}) { + const pathname = usePathname(); + + const { + isPublicRoute, + hideSidebar, + mainClass, + } = useMemo( + () => getLayoutState(pathname), + [pathname] + ); + return (