From 33bd0fdd2aff6225662e14de59424016888e8f69 Mon Sep 17 00:00:00 2001 From: bicochan Date: Mon, 23 Jun 2025 16:29:34 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20LNB=20=EB=8F=99=EC=9E=91=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/components/src/ui/lnb/index.tsx | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/packages/common/components/src/ui/lnb/index.tsx b/packages/common/components/src/ui/lnb/index.tsx index 40249fee5..60bb9ebdc 100644 --- a/packages/common/components/src/ui/lnb/index.tsx +++ b/packages/common/components/src/ui/lnb/index.tsx @@ -40,8 +40,7 @@ export function LNB({ enabled: !viewOnly, }); - const [openMenuIds, setOpenMenuIds] = useState([]); - const userClosedMenusRef = useRef(new Set()); + const [defaultOpenMenuIds, setDefaultOpenMenuIds] = useState([]); const prevPathRef = useRef(currentPath); function isPathMatched(path: string) { @@ -70,14 +69,13 @@ export function LNB({ findMatchedMenus(menuList); if (matchedMenuIds.length > 0) { - const filteredIds = matchedMenuIds.filter( - (id) => !userClosedMenusRef.current.has(id), - ); - setOpenMenuIds((prev) => [...new Set([...prev, ...filteredIds])]); + setDefaultOpenMenuIds((prev) => [ + ...new Set([...prev, ...matchedMenuIds]), + ]); } if (prevPathRef.current !== currentPath) { - setOpenMenuIds(matchedMenuIds); + setDefaultOpenMenuIds(matchedMenuIds); prevPathRef.current = currentPath; } }, [menuList, currentPath]); @@ -133,29 +131,11 @@ export function LNB({ } function MenuGroup({ item }: { item: MenuItem }) { - const { open: isSidebarOpen, setOpen } = useSidebar(); - const isOpen = openMenuIds.includes(item.menuCd); - - const handleOpenChange = (open: boolean) => { - if (!isSidebarOpen) setOpen(true); - if (open) { - // 열 때는 부모들도 함께 열기 - if (!openMenuIds.includes(item.menuCd)) { - const parentIds = getParentIds(item.menuCd)(menuList ?? []); - setOpenMenuIds((prev) => [...prev, ...parentIds, item.menuCd]); - } - userClosedMenusRef.current.delete(item.menuCd); - } else { - // 닫을 때는 현재 메뉴만 닫기 - setOpenMenuIds((prev) => prev.filter((id) => id !== item.menuCd)); - userClosedMenusRef.current.add(item.menuCd); - } - }; + const { open: isSidebarOpen } = useSidebar(); return (