[st] - tab & menu 로직 수정

This commit is contained in:
2026-06-15 16:34:02 +09:00
parent 44c5d66afa
commit f21dde8f7d
13 changed files with 690 additions and 23 deletions
+15 -2
View File
@@ -4,6 +4,8 @@ import { createJSONStorage, persist } from "zustand/middleware";
import type { MenuItem } from "@/entities/menu";
import { MenuAuthorityApi } from "@/entities/menu-authority";
import type { PageMenuAuthority } from "@/entities/menu-authority/model/menu-authority-interface";
import { isBbsNoticeMenu } from "@/shared/lib/bbs-notice-menu";
import { resolveStatisticsTabId } from "@/shared/lib/statistics-menu-url";
export interface Tab {
id: string; // 고유 ID (urlPath)
@@ -101,11 +103,18 @@ function tabForPersist(tab: Tab): Tab {
};
}
function normalizePersistedTab(tab: Tab): Tab {
const tabId = resolveStatisticsTabId(tab.urlPath || tab.id);
return tabId === tab.id ? tab : { ...tab, id: tabId };
}
function sanitizePersistedTabsAndActive(
tabs: Tab[],
activeTabId: string | null,
): { tabs: Tab[]; activeTabId: string | null } {
let nextTabs = Array.isArray(tabs) ? tabs : [];
let nextTabs = Array.isArray(tabs)
? tabs.filter((tab) => !isBbsNoticeMenu(tab.menuItem)).map(normalizePersistedTab)
: [];
if (nextTabs.length > MAX_TABS) nextTabs = nextTabs.slice(0, MAX_TABS);
if (nextTabs.length === 0) {
@@ -130,8 +139,12 @@ const useTabStoreHook = create<TabStore>()(
activeTabId: null,
menuList: null,
addTab: (menuItem: MenuItem) => {
if (isBbsNoticeMenu(menuItem)) {
return false;
}
const { tabs, menuList } = get();
const tabId = menuItem.urlPath || "";
const tabId = resolveStatisticsTabId(menuItem.urlPath || "");
const existingTab = tabs.find((tab) => tab.id === tabId);