Merge branch 'iipbs/st/dev' of https://www.onasys.co.kr:3000/ONAANDALL/frontend
This commit is contained in:
@@ -1,26 +1,28 @@
|
||||
"use client";
|
||||
|
||||
import { Suspense, useRef, useEffect } from "react";
|
||||
import { Suspense, useEffect, useRef } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import { useTabStore } from "@/store/tab-store";
|
||||
import { useAdminStore } from "@/store/admin-store";
|
||||
import Dashboard from "@/components/Dashboard";
|
||||
|
||||
import { SkeletonPage } from "@/shared/ui/skeleton-page";
|
||||
|
||||
import "@rsone/components/index.css";
|
||||
|
||||
import Dashboard from "@/components/statistics/Dashboard";
|
||||
import { useAdminStore } from "@/store/admin-store";
|
||||
import { useTabStore } from "@/store/tab-store";
|
||||
|
||||
const StatisticsPage = () => {
|
||||
const { tabs, activeTabId } = useTabStore();
|
||||
const fetchAdminInfo = useAdminStore((state) => state.fetchAdminInfo);
|
||||
|
||||
|
||||
// 컴포넌트 캐시를 useRef로 유지 (재렌더링 시에도 유지됨)
|
||||
const componentCache = useRef(new Map<string, React.ComponentType>());
|
||||
|
||||
// 닫힌 탭의 컴포넌트는 캐시에서 제거 (메모리 정리)
|
||||
useEffect(() => {
|
||||
const currentTabIds = new Set(tabs.map(tab => tab.id));
|
||||
const currentTabIds = new Set(tabs.map((tab) => tab.id));
|
||||
const cachedTabIds = Array.from(componentCache.current.keys());
|
||||
|
||||
|
||||
cachedTabIds.forEach((cachedId) => {
|
||||
if (!currentTabIds.has(cachedId)) {
|
||||
componentCache.current.delete(cachedId);
|
||||
@@ -48,15 +50,15 @@ const StatisticsPage = () => {
|
||||
if (!componentCache.current.has(tab.id)) {
|
||||
const componentName = tab.urlPath;
|
||||
const parentComponentName = tab.parentEngNm;
|
||||
|
||||
|
||||
const DynamicComponent = dynamic(
|
||||
() => import(`@/components/statistics/${parentComponentName}/${componentName}`),
|
||||
{
|
||||
ssr: false,
|
||||
loading: () => <SkeletonPage />
|
||||
}
|
||||
() =>
|
||||
import(
|
||||
`@/components/statistics${parentComponentName ? `/${parentComponentName}` : ""}/${componentName}`
|
||||
),
|
||||
{ ssr: false, loading: () => <SkeletonPage /> },
|
||||
);
|
||||
|
||||
|
||||
componentCache.current.set(tab.id, DynamicComponent);
|
||||
}
|
||||
|
||||
@@ -68,7 +70,7 @@ const StatisticsPage = () => {
|
||||
return (
|
||||
<div
|
||||
key={tab.id}
|
||||
style={{ display: isActive ? 'block' : 'none' }}
|
||||
style={{ display: isActive ? "block" : "none" }}
|
||||
>
|
||||
<Suspense fallback={<SkeletonPage />}>
|
||||
<Component />
|
||||
@@ -80,4 +82,4 @@ const StatisticsPage = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default StatisticsPage;
|
||||
export default StatisticsPage;
|
||||
|
||||
Reference in New Issue
Block a user