import React, { useEffect } from 'react' import { useShallow } from 'zustand/react/shallow' import { RiLayoutLeft2Line, RiLayoutRight2Line } from '@remixicon/react' import NavLink from './navLink' import type { NavIcon } from './navLink' import AppBasic from './basic' import AppInfo from './app-info' import DatasetInfo from './dataset-info' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import { useStore as useAppStore } from '@/app/components/app/store' import cn from '@/utils/classnames' import { useSearchParams } from 'next/navigation' export type IAppDetailNavProps = { iconType?: 'app' | 'dataset' | 'notion' title: string desc: string isExternal?: boolean icon: string icon_background: string navigation: Array<{ name: string href: string icon: NavIcon selectedIcon: NavIcon }> extraInfo?: (modeState: string) => React.ReactNode } const AppDetailNav = ({ title, desc, isExternal, icon, icon_background, navigation, extraInfo, iconType = 'app' }: IAppDetailNavProps) => { const { appSidebarExpand, setAppSiderbarExpand } = useAppStore(useShallow(state => ({ appSidebarExpand: state.appSidebarExpand, setAppSiderbarExpand: state.setAppSiderbarExpand, }))) const media = useBreakpoints() const isMobile = media === MediaType.mobile const expand = appSidebarExpand === 'expand' const handleToggle = (state: string) => { setAppSiderbarExpand(state === 'expand' ? 'collapse' : 'expand') } useEffect(() => { if (appSidebarExpand) { localStorage.setItem('app-detail-collapse-or-expand', appSidebarExpand) setAppSiderbarExpand(appSidebarExpand) } }, [appSidebarExpand, setAppSiderbarExpand]) const searchParams = useSearchParams() // 从 router 查询参数,若有 sidebar选项,按照参数设置,没有的话,默认是展示内容 const showSidebar = !(searchParams?.get('sidebar')) || (searchParams?.get('sidebar') === '1') // console.log('searchParams?.get("sidebar"): ', searchParams?.get('sidebar'),!(searchParams?.get('sidebar')) , (searchParams?.get('sidebar') === '1')) // console.log('showSidebar: ', showSidebar) // 如果showSidebar为false,不显示 if (!showSidebar) return null; return (
{iconType === 'app' && ( )} {iconType === 'dataset' && ( )} {!['app', 'dataset'].includes(iconType) && ( )}
{ !isMobile && (
handleToggle(appSidebarExpand)} > { expand ? : }
) }
) } export default React.memo(AppDetailNav)