261012_01_FST: first commit
This commit is contained in:
45
src/components/app-shell/AppMainLayout.tsx
Normal file
45
src/components/app-shell/AppMainLayout.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
"use client";
|
||||
|
||||
import type { Route } from "next";
|
||||
import { useMemo, useState, type ReactNode } from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import { KriMainLayout } from "@/components/layout/KriMainLayout";
|
||||
import { AppHeader } from "./AppHeader";
|
||||
import { AppSidebar } from "./AppSidebar";
|
||||
import { sideMenus, topMenus } from "@/config/menu.data";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
|
||||
export function AppMainLayout({ children }: { children: ReactNode }) {
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
const { auth } = useAuth();
|
||||
const [menuOpen, setMenuOpen] = useState(true);
|
||||
|
||||
const activeMenuId = useMemo(
|
||||
() => topMenus.find((item) => item.path && (pathname === item.path || pathname.startsWith(`${item.path}/`)))?.id,
|
||||
[pathname],
|
||||
);
|
||||
|
||||
const navigate = (path: string) => router.push(path as Route);
|
||||
const hasSidebar = sideMenus.length > 0;
|
||||
|
||||
return (
|
||||
<KriMainLayout
|
||||
sidebarOpen={hasSidebar && menuOpen}
|
||||
onSidebarOpenChange={setMenuOpen}
|
||||
header={
|
||||
<AppHeader
|
||||
menuOpen={menuOpen}
|
||||
showMenuButton={hasSidebar}
|
||||
activeMenuId={activeMenuId}
|
||||
user={auth.user}
|
||||
onToggleMenu={() => setMenuOpen((current) => !current)}
|
||||
onNavigate={navigate}
|
||||
/>
|
||||
}
|
||||
sidebar={hasSidebar ? <AppSidebar items={sideMenus} isOpen={menuOpen} pathname={pathname} onNavigate={navigate} /> : undefined}
|
||||
>
|
||||
{children}
|
||||
</KriMainLayout>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user