import React, { useEffect, useState } from 'react' import { usePathname } from 'next/navigation' import { useShallow } from 'zustand/react/shallow' import { RiLayoutLeft2Line, RiLayoutRight2Line } from '@remixicon/react' import NavLink from './navLink' import type { NavIcon } from './navLink' import AppInfo from './app-info' import DatasetInfo from './dataset-info' import AppSidebarDropdown from './app-sidebar-dropdown' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import { useStore as useAppStore } from '@/app/components/app/store' import { useEventEmitterContextContext } from '@/context/event-emitter' import cn from '@/utils/classnames' export type IAppDetailNavProps = { iconType?: 'app' | 'dataset' | 'notion' navigation: Array<{ name: string href: string icon: NavIcon selectedIcon: NavIcon disabled?: boolean }> extraInfo?: (modeState: string) => React.ReactNode } const AppDetailNav = ({ navigation, extraInfo, iconType = 'app', }: IAppDetailNavProps) => { const { appSidebarExpand, setAppSidebarExpand } = useAppStore(useShallow(state => ({ appSidebarExpand: state.appSidebarExpand, setAppSidebarExpand: state.setAppSidebarExpand, }))) const media = useBreakpoints() const isMobile = media === MediaType.mobile const expand = appSidebarExpand === 'expand' const handleToggle = (state: string) => { setAppSidebarExpand(state === 'expand' ? 'collapse' : 'expand') } // // Check if the current path is a workflow canvas & fullscreen const pathname = usePathname() const inWorkflowCanvas = pathname.endsWith('/workflow') const workflowCanvasMaximize = localStorage.getItem('workflow-canvas-maximize') === 'true' const [hideHeader, setHideHeader] = useState(workflowCanvasMaximize) const { eventEmitter } = useEventEmitterContextContext() eventEmitter?.useSubscription((v: any) => { if (v?.type === 'workflow-canvas-maximize') setHideHeader(v.payload) }) useEffect(() => { if (appSidebarExpand) { localStorage.setItem('app-detail-collapse-or-expand', appSidebarExpand) setAppSidebarExpand(appSidebarExpand) } }, [appSidebarExpand, setAppSidebarExpand]) if (inWorkflowCanvas && hideHeader) { return (
) } return (
{iconType === 'app' && ( )} {iconType !== 'app' && ( )}
{ !isMobile && (
handleToggle(appSidebarExpand)} > { expand ? : }
) }
) } export default React.memo(AppDetailNav)