260615_01_FST: First Commit
This commit is contained in:
61
src/components/layout/MainLayout.tsx
Normal file
61
src/components/layout/MainLayout.tsx
Normal file
@@ -0,0 +1,61 @@
|
||||
"use client";
|
||||
|
||||
import {ReactNode, useEffect, useState} from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import { Header } from "@/components/layout/Header";
|
||||
import {TOP_MENUS} from "@/config/menu.data";
|
||||
import {useAuth} from "@/hooks/useAuth";
|
||||
import type {LoginUser} from "@/types/auth";
|
||||
import {useMounted} from "@/hooks/useMounted";
|
||||
type MainLayoutProps = {
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const activeTop = TOP_MENUS.find((m) => m.match?.(pathname)) ?? TOP_MENUS[0];
|
||||
const { auth, isMonitoring } = useAuth();
|
||||
const mounted = useMounted();
|
||||
|
||||
const [userInfo, setUserInfo] = useState<LoginUser|undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
if (!mounted) return;
|
||||
|
||||
if(auth.user){
|
||||
setUserInfo(auth.user);
|
||||
}
|
||||
else{
|
||||
//router.replace("/logout");
|
||||
}
|
||||
}, [auth.user, mounted, router])
|
||||
|
||||
const movePage = (path: string) => {
|
||||
router.push(path);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className="bg-gray-50 flex flex-col min-h-screen"
|
||||
>
|
||||
{/* 헤더 - 고정 폰트 크기 */}
|
||||
<Header
|
||||
isMonitoring={isMonitoring}
|
||||
userInfo={userInfo}
|
||||
activeTopId={activeTop.id}
|
||||
onNavigate={movePage}
|
||||
/>
|
||||
|
||||
{/* 본문 */}
|
||||
<div className="flex flex-1 min-h-0">
|
||||
{/* 메인 콘텐츠만 가변 폰트 크기 적용 */}
|
||||
<main className="flex-1 p-4">
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MainLayout;
|
||||
Reference in New Issue
Block a user