260123_ENH : Layout가지 완성된 최초 commit

This commit is contained in:
2026-01-23 11:58:39 +09:00
parent cd4e47ce22
commit 649e7f4b26
81 changed files with 5608 additions and 343 deletions

View File

@@ -0,0 +1,127 @@
"use client";
import {ReactNode, useState} from "react";
import { usePathname, useRouter } from "next/navigation";
import {topMenus, totalSubMenus, categorySubMenus} from "@/config/menu.data";
import Header from "./Header";
import SubMenu from "./SubMenu";
import TotalFilter from "@/components/layout/TotalFilter";
import CategoryFilter, {CategoryFilterValue} from "@/components/layout/CategoryFilter";
import {cn} from "@/lib/utils";
import {Button} from "@/components/ui/button";
import {SelectedMap} from "@/types/common";
import {categoryTarget, totalFilters} from "@/config/filter.data";
import {CategoryTargetData, CategoryTargetType} from "@/config/filter.types";
type MainLayoutProps = {
children: ReactNode;
};
const buildDefaultTotalValue = (): SelectedMap => {
const init: SelectedMap = {};
totalFilters.forEach((f) => {
// "전체"가 있으면 그 value, 없으면 첫 번째 값
const all = f.children.find((c) => c.label === "전체");
init[f.variable] = all?.value ?? f.children[0]?.value ?? "";
});
return init;
};
export const buildDefaultCategoryValue = (): CategoryFilterValue => {
const initType = {label:"보유", value:CategoryTargetType.PENETRATION}
const firstTarget = categoryTarget.find((x) => x.type === initType.value)?.children?.[0]?.target;
return {
product: "냉장고",
type: initType,
target: firstTarget ?? CategoryTargetData.PROFILE,
};
};
const MainLayout = ({ children }: MainLayoutProps) => {
const router = useRouter();
const pathname = usePathname();
const isTotal = pathname.startsWith("/total");
const activeTop = topMenus.find((m) => m.match?.(pathname)) ?? topMenus[0];
const subMenus = isTotal ? totalSubMenus : categorySubMenus;
const activeSub = subMenus.find((m) => m.path.startsWith(pathname)) ?? subMenus[0];
const [isTotalFilterOpen, setIsTotalFilterOpen] = useState(true);
const [isCategoryFilterOpen, setIsCategoryFilterOpen] = useState(true);
const isFilterOpen = isTotal ? isTotalFilterOpen : isCategoryFilterOpen;
const [totalValue, setTotalValue] = useState<SelectedMap>(() => buildDefaultTotalValue());
const [categoryValue, setCategoryValue] = useState<CategoryFilterValue>(() => buildDefaultCategoryValue());
const movePage = (path: string) => {
router.push(path);
};
const toggleFilter = () => {
if (isTotal) setIsTotalFilterOpen((v) => !v);
else setIsCategoryFilterOpen((v) => !v);
};
const handleExcelDownload = async () => {
// TODO: 다운로드 구현 필요
console.log("Excel download:", { pathname, top: activeTop.id, sub: activeSub.id });
};
return (
<div className="min-h-screen flex flex-col bg-transparent">
<Header
activeTopId={activeTop.id}
onNavigate={movePage}
/>
<div className="flex-1 min-h-0 flex flex-col bg-lg-main-body p-1 pl-6">
<SubMenu
subMenu={subMenus}
activeSubId={activeSub.id}
onNavigate={movePage}
/>
<div className="flex-1 min-h-0 flex flex-col pr-4">
<div className="bg-card lg-tab-content flex-1 min-h-0">
<div className="shrink-0 flex items-center justify-between px-2 py-1">
<button
type="button"
onClick={toggleFilter}
className={cn(
"inline-flex items-center gap-2 font-semibold text-gray-900 content-text-sm",
"select-none"
)}
>
필터 <span className="text-sm leading-none">{isFilterOpen ? "▲" : "▼"}</span>
</button>
<Button
variant="excel"
className="h-8 px-3 text-sm font-semibold content-text-sm"
onClick={handleExcelDownload}>
Excel 다운로드
</Button>
</div>
{isFilterOpen && (
<div className="shrink-0">
{isTotal ? (
<TotalFilter filters={totalFilters} value={totalValue} onChange={setTotalValue} />
) : (
<CategoryFilter value={categoryValue} onChange={setCategoryValue} />
)}
</div>
)}
{/* ✅ 실제 콘텐츠만 스크롤 */}
<div className="flex-1 min-h-0 overflow-auto">
<div className="p-3">{children}</div>
</div>
</div>
</div>
</div>
</div>
);
}
export default MainLayout;