import HomeSidebar from '@/app/home/components/home-sidebar/HomeSidebar'; import SurveyWidget from '@/app/home/components/survey/SurveyWidget'; import React, { useState, useCallback, useMemo, useEffect, Suspense, } from 'react'; import { SidebarChildVO } from '@/app/home/components/home-sidebar/HomeSidebarChild'; import { SidebarDataProvider, useSidebarData, } from '@/app/home/components/home-sidebar/SidebarDataContext'; import { I18nObject } from '@/app/infra/entities/common'; import { userInfo, systemInfo, initializeUserInfo, initializeSystemInfo, } from '@/app/infra/http'; import { useNavigate, useLocation } from 'react-router-dom'; import { Link } from 'react-router-dom'; import { extractI18nObject } from '@/i18n/I18nProvider'; import { CircleHelp } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { SidebarInset, SidebarProvider, SidebarTrigger, } from '@/components/ui/sidebar'; import { Separator } from '@/components/ui/separator'; import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from '@/components/ui/breadcrumb'; import { PluginInstallTaskProvider, PluginInstallProgressDialog, } from '@/app/home/plugins/components/plugin-install-task'; // Routes that belong to the "Extensions" section const EXTENSIONS_ROUTES = [ '/home/plugins', '/home/market', '/home/mcp', '/home/plugin-pages', ]; function isExtensionsRoute(pathname: string): boolean { return EXTENSIONS_ROUTES.some( (route) => pathname === route || pathname.startsWith(route + '/'), ); } export default function HomeLayout({ children, }: Readonly<{ children: React.ReactNode; }>) { const navigate = useNavigate(); // Initialize user info if not already initialized useEffect(() => { if (!userInfo) { initializeUserInfo(); } }, []); // Auto-redirect to wizard on first visit (wizard not yet completed on this instance) useEffect(() => { const checkWizard = async () => { try { // Always re-fetch to ensure we have the latest wizard_status from backend await initializeSystemInfo(); if (systemInfo.wizard_status === 'none') { navigate('/wizard'); } } catch { // If fetching system info fails, don't redirect } }; checkWizard(); }, [navigate]); return ( {children} ); } function HomeLayoutInner({ children }: { children: React.ReactNode }) { const [title, setTitle] = useState(''); const [helpLink, setHelpLink] = useState({ en_US: '', zh_Hans: '', }); const { detailEntityName } = useSidebarData(); const location = useLocation(); const pathname = location.pathname; const { t } = useTranslation(); const onSelectedChangeAction = useCallback((child: SidebarChildVO) => { setTitle(child.name); setHelpLink(child.helpLink); }, []); // Memoize the main content area to prevent re-renders when sidebar state changes const mainContent = useMemo(() => children, [children]); const resolvedHelpLink = extractI18nObject(helpLink); // Determine breadcrumb section label and default link based on current route const isExtensions = isExtensionsRoute(pathname); const sectionLabel = isExtensions ? t('sidebar.extensions') : t('sidebar.home'); const sectionLink = isExtensions ? '/home/plugins' : '/home/monitoring'; return ( }>
{sectionLabel} {title} {detailEntityName && ( <> {detailEntityName} )} {resolvedHelpLink && ( <> )}
{mainContent}
); }