251121_01_ENH : 로그인 및 인증 저장, api통신 시 자동으로 accessKey 붙게 조치
This commit is contained in:
17
src/components/common/LoadingOverlay.tsx
Normal file
17
src/components/common/LoadingOverlay.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { useAtomValue } from "jotai";
|
||||
import { loadingAtom } from "@/store/jotai/loading";
|
||||
|
||||
export function LoadingOverlay() {
|
||||
const isLoading = useAtomValue(loadingAtom);
|
||||
|
||||
if (!isLoading) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-[9999] bg-black/70 flex items-center justify-center">
|
||||
{/* 심플 로딩 인디케이터 */}
|
||||
<div className="h-12 w-12 rounded-full border-4 border-gray-400 border-t-white animate-spin" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
120
src/components/layout/Header.tsx
Normal file
120
src/components/layout/Header.tsx
Normal file
@@ -0,0 +1,120 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Menu, X, ZoomIn, ZoomOut, LogOut } from "lucide-react";
|
||||
import Image from "next/image";
|
||||
import { topMenus } from "@/config/menu.data";
|
||||
|
||||
interface HeaderProps {
|
||||
isMain: boolean;
|
||||
menuOpen: boolean;
|
||||
activeTopId: string;
|
||||
fontSize: number;
|
||||
handleIsProjectMenu: (isProjectMenu: boolean) => void;
|
||||
onToggleMenu: () => void;
|
||||
onNavigate: (path: string) => void;
|
||||
decreaseFontSize: () => void;
|
||||
increaseFontSize: () => void;
|
||||
}
|
||||
|
||||
export const Header = ({
|
||||
isMain,
|
||||
menuOpen,
|
||||
activeTopId,
|
||||
fontSize,
|
||||
handleIsProjectMenu,
|
||||
onToggleMenu,
|
||||
onNavigate,
|
||||
decreaseFontSize,
|
||||
increaseFontSize,
|
||||
}: HeaderProps) => {
|
||||
return (
|
||||
<header className="bg-white border-b border-gray-200 sticky top-0 z-40">
|
||||
<div className="flex items-center justify-between px-4 h-16">
|
||||
<div className="flex items-center gap-4">
|
||||
{/* 햄버거 메뉴 */}
|
||||
<div className="w-5">
|
||||
{isMain? null :
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="cursor-pointer"
|
||||
onClick={() => onToggleMenu()}
|
||||
>
|
||||
{menuOpen ? <X className="w-5 h-5" /> : <Menu className="w-5 h-5" />}
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
{/* 로고 */}
|
||||
<div
|
||||
className="flex items-center gap-2 cursor-pointer"
|
||||
onClick={() => onNavigate("/")}
|
||||
>
|
||||
<div className="w-20 h-10 flex items-center justify-center">
|
||||
<Image
|
||||
src="/kri_logo.png"
|
||||
alt="KRI 로고"
|
||||
width={120}
|
||||
height={40}
|
||||
className="object-contain"
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 상단 메뉴 */}
|
||||
<nav className="flex items-center gap-1 ml-25">
|
||||
{topMenus.map((m) => (
|
||||
<Button
|
||||
key={m.id}
|
||||
variant={activeTopId === m.id ? "default" : "ghost"}
|
||||
className="cursor-pointer"
|
||||
onClick={() => {
|
||||
handleIsProjectMenu(m.id === "project");
|
||||
onNavigate(m.path);
|
||||
}}
|
||||
>
|
||||
{m.label}
|
||||
</Button>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{/* 우측 컨트롤 */}
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="flex items-center gap-1 border-r pr-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => decreaseFontSize()}
|
||||
title="폰트 작게"
|
||||
>
|
||||
<ZoomOut className="w-4 h-4" />
|
||||
</Button>
|
||||
<span className="text-xs text-gray-500 min-w-[3rem] text-center">
|
||||
{fontSize}px
|
||||
</span>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => increaseFontSize()}
|
||||
title="폰트 크게"
|
||||
>
|
||||
<ZoomIn className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<span className="text-sm text-gray-600 hidden sm:inline">admin</span>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="gap-2"
|
||||
onClick={() => onNavigate("/logout")}
|
||||
>
|
||||
<LogOut className="w-4 h-4" />
|
||||
<span className="hidden sm:inline">로그아웃</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
127
src/components/layout/MainLayout.tsx
Normal file
127
src/components/layout/MainLayout.tsx
Normal file
@@ -0,0 +1,127 @@
|
||||
"use client";
|
||||
|
||||
import {useState, useEffect, ReactNode} from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import { Header } from "@/components/layout/Header";
|
||||
import { Sidebar } from "@/components/layout/Sidebar";
|
||||
import {useFontSize} from "@/hooks/useFontSize";
|
||||
import {projectSideMenus, manageSideMenus, topMenus} from "@/config/menu.data";
|
||||
import commonConst from "@/config/commonConst";
|
||||
|
||||
type MainLayoutProps = {
|
||||
children: ReactNode;
|
||||
initialFontSize: number; // 🔥 추가
|
||||
};
|
||||
|
||||
const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
const [isProjectMenu, setIsProjectMenu] = useState(false);
|
||||
const [menuOpen, setMenuOpen] = useState(true);
|
||||
const [fontSize, setFontSize] = useFontSize(initialFontSize, { hydrateFromCookie: false });
|
||||
|
||||
const isMain = pathname === "/";
|
||||
const activeTop = topMenus.find((m) => m.match?.(pathname)) ?? topMenus[0];
|
||||
const sideMenus = pathname.startsWith("/manage") ? manageSideMenus : projectSideMenus;
|
||||
|
||||
// 2단 메뉴 open 상태
|
||||
const [openMenus, setOpenMenus] = useState<Record<string, boolean>>(() => {
|
||||
const initial: Record<string, boolean> = {};
|
||||
|
||||
sideMenus.forEach((item) => {
|
||||
if (
|
||||
item.children &&
|
||||
item.children.some(
|
||||
(child) =>
|
||||
pathname === child.path || pathname.startsWith(child.path + "/")
|
||||
)
|
||||
) {
|
||||
initial[item.id] = true;
|
||||
}
|
||||
});
|
||||
return initial;
|
||||
});
|
||||
|
||||
const handleIsProjectMenu = (isProject: boolean) => {
|
||||
setIsProjectMenu(isProject);
|
||||
}
|
||||
|
||||
const movePage = (path: string) => {
|
||||
router.push(path);
|
||||
};
|
||||
|
||||
const toggleSideMenu = (id: string) => {
|
||||
setOpenMenus((prev) => ({ ...prev, [id]: !prev[id] }));
|
||||
};
|
||||
|
||||
const decreaseFontSize = () =>{
|
||||
setFontSize(Math.max(commonConst.fontSizeMin, fontSize - 2));
|
||||
}
|
||||
|
||||
const increaseFontSize = () =>{
|
||||
setFontSize(Math.min(commonConst.fontSizeMax, fontSize + 2));
|
||||
}
|
||||
|
||||
// CSS 변수 동기화
|
||||
useEffect(() => {
|
||||
if (typeof document === "undefined") return;
|
||||
document.documentElement.style.setProperty(
|
||||
"--content-font-size",
|
||||
`${fontSize}px`,
|
||||
);
|
||||
}, [fontSize]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
{/* 헤더 - 고정 폰트 크기 */}
|
||||
<Header
|
||||
isMain={isMain}
|
||||
menuOpen={menuOpen}
|
||||
activeTopId={activeTop.id}
|
||||
fontSize={fontSize}
|
||||
handleIsProjectMenu={handleIsProjectMenu}
|
||||
onToggleMenu={() => setMenuOpen((prev) => !prev)}
|
||||
onNavigate={movePage}
|
||||
decreaseFontSize={decreaseFontSize}
|
||||
increaseFontSize={increaseFontSize}
|
||||
/>
|
||||
|
||||
{/* 본문 */}
|
||||
<div className="flex">
|
||||
{/* 사이드바 - 고정 폰트 크기 */}
|
||||
{!isMain && (
|
||||
<Sidebar
|
||||
isProjectMenu={isProjectMenu}
|
||||
sideMenus={sideMenus}
|
||||
isOpen={menuOpen}
|
||||
pathname={pathname}
|
||||
openMenus={openMenus}
|
||||
onToggleMenu={toggleSideMenu}
|
||||
onNavigate={movePage}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 메인 콘텐츠만 가변 폰트 크기 적용 */}
|
||||
<main
|
||||
className="flex-1"
|
||||
// 전역 CSS 변수(--content-font-size)를 실제 렌더에 적용
|
||||
// SSR 단계에서의 초기 폰트 값을 FOUC 없이 유지하기 위해 fallback을 함께 지정
|
||||
style={{ fontSize: `var(--content-font-size, ${initialFontSize}px)` }}
|
||||
>
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
|
||||
{/* 모바일 오버레이 */}
|
||||
{!isMain && menuOpen && (
|
||||
<div
|
||||
className="fixed inset-0 z-20 lg:hidden"
|
||||
onClick={() => setMenuOpen(false)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MainLayout;
|
||||
130
src/components/layout/Sidebar.tsx
Normal file
130
src/components/layout/Sidebar.tsx
Normal file
@@ -0,0 +1,130 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ChevronDown } from "lucide-react";
|
||||
import { SideMenuItem } from "@/config/menu.types";
|
||||
|
||||
interface SidebarProps {
|
||||
isProjectMenu: boolean;
|
||||
sideMenus: SideMenuItem[];
|
||||
isOpen: boolean;
|
||||
pathname: string;
|
||||
openMenus: Record<string, boolean>;
|
||||
onToggleMenu: (id: string) => void;
|
||||
onNavigate: (path: string) => void;
|
||||
}
|
||||
|
||||
export const Sidebar = ({
|
||||
isProjectMenu,
|
||||
sideMenus,
|
||||
isOpen,
|
||||
pathname,
|
||||
openMenus,
|
||||
onToggleMenu,
|
||||
onNavigate,
|
||||
}: SidebarProps) => {
|
||||
const isSideActive = (item: SideMenuItem, current: string) => {
|
||||
if (item.path) {
|
||||
return current === item.path || current.startsWith(item.path + "/");
|
||||
}
|
||||
if (item.children) {
|
||||
return item.children.some(
|
||||
(c) => current === c.path || current.startsWith(c.path + "/")
|
||||
);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
return (
|
||||
<aside
|
||||
className={`
|
||||
fixed lg:static top-16 lg:top-0 left-0
|
||||
h-[calc(100vh-4rem)] bg-white border-r border-gray-200
|
||||
transition-all duration-300 z-30 overflow-y-auto
|
||||
lg:translate-x-0
|
||||
${
|
||||
isOpen
|
||||
? "w-64 translate-x-0"
|
||||
: "w-64 -translate-x-full lg:w-0 lg:border-r-0"
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div className="p-4 space-y-4 overflow-y-auto h-full">
|
||||
{isProjectMenu?
|
||||
<div className="space-y-2">
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="프로젝트 검색..."
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
: null
|
||||
}
|
||||
|
||||
{/* 좌측 메뉴 */}
|
||||
<nav className="space-y-1">
|
||||
{sideMenus.map((item) => {
|
||||
const hasChildren = !!item.children?.length;
|
||||
const opened = openMenus[item.id] ?? false;
|
||||
const active = isSideActive(item, pathname);
|
||||
|
||||
if (!hasChildren && item.path) {
|
||||
return (
|
||||
<Button
|
||||
key={item.id}
|
||||
variant={active ? "secondary" : "ghost"}
|
||||
className="w-full justify-start"
|
||||
onClick={() => onNavigate(item.path!)}
|
||||
>
|
||||
<item.icon className="w-4 h-4" />
|
||||
<span className="ml-2">{item.label}</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div key={item.id} className="space-y-1">
|
||||
<Button
|
||||
variant={active ? "secondary" : "ghost"}
|
||||
className="w-full justify-between"
|
||||
onClick={() => onToggleMenu(item.id)}
|
||||
>
|
||||
<span className="flex items-center">
|
||||
<item.icon className="w-4 h-4" />
|
||||
<span className="ml-2">{item.label}</span>
|
||||
</span>
|
||||
<ChevronDown
|
||||
className={`w-4 h-4 transition-transform ${
|
||||
opened ? "rotate-180" : ""
|
||||
}`}
|
||||
/>
|
||||
</Button>
|
||||
|
||||
{opened && item.children && (
|
||||
<div className="ml-6 space-y-1">
|
||||
{item.children.map((child) => {
|
||||
const childActive =
|
||||
pathname === child.path ||
|
||||
pathname.startsWith(child.path + "/");
|
||||
return (
|
||||
<Button
|
||||
key={child.id}
|
||||
variant={childActive ? "secondary" : "ghost"}
|
||||
className="w-full justify-start"
|
||||
onClick={() => onNavigate(child.path)}
|
||||
>
|
||||
<span className="ml-1">{child.label}</span>
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
};
|
||||
13
src/components/providers/AppProvider.tsx
Normal file
13
src/components/providers/AppProvider.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { Provider as JotaiProvider } from "jotai";
|
||||
import { LoadingOverlay } from "@/components/common/LoadingOverlay";
|
||||
|
||||
export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<JotaiProvider>
|
||||
<LoadingOverlay />
|
||||
{children}
|
||||
</JotaiProvider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user