mirror of
				https://github.com/langgenius/dify.git
				synced 2025-10-31 10:53:02 +00:00 
			
		
		
		
	 d186daa131
			
		
	
	
		d186daa131
		
			
		
	
	
	
	
		
			
			Signed-off-by: -LAN- <laipz8200@outlook.com> Co-authored-by: Hash Brown <hi@xzd.me> Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: GareArc <chen4851@purdue.edu> Co-authored-by: Byron.wang <byron@dify.ai> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: Garfield Dai <dai.hai@foxmail.com> Co-authored-by: KVOJJJin <jzongcode@gmail.com> Co-authored-by: Alexi.F <654973939@qq.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com> Co-authored-by: kautsar_masuara <61046989+izon-masuara@users.noreply.github.com> Co-authored-by: achmad-kautsar <achmad.kautsar@insignia.co.id> Co-authored-by: Xin Zhang <sjhpzx@gmail.com> Co-authored-by: kelvintsim <83445753+kelvintsim@users.noreply.github.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: Zixuan Cheng <61724187+Theysua@users.noreply.github.com>
		
			
				
	
	
		
			111 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			111 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| 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 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'
 | |
| 
 | |
| export type IAppDetailNavProps = {
 | |
|   iconType?: 'app' | 'dataset' | 'notion'
 | |
|   navigation: Array<{
 | |
|     name: string
 | |
|     href: string
 | |
|     icon: NavIcon
 | |
|     selectedIcon: NavIcon
 | |
|   }>
 | |
|   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')
 | |
|   }
 | |
| 
 | |
|   useEffect(() => {
 | |
|     if (appSidebarExpand) {
 | |
|       localStorage.setItem('app-detail-collapse-or-expand', appSidebarExpand)
 | |
|       setAppSidebarExpand(appSidebarExpand)
 | |
|     }
 | |
|   }, [appSidebarExpand, setAppSidebarExpand])
 | |
| 
 | |
|   return (
 | |
|     <div
 | |
|       className={`
 | |
|         flex shrink-0 flex-col border-r border-divider-burn bg-background-default-subtle transition-all
 | |
|         ${expand ? 'w-[216px]' : 'w-14'}
 | |
|       `}
 | |
|     >
 | |
|       <div
 | |
|         className={`
 | |
|           shrink-0
 | |
|           ${expand ? 'p-2' : 'p-1'}
 | |
|         `}
 | |
|       >
 | |
|         {iconType === 'app' && (
 | |
|           <AppInfo expand={expand} />
 | |
|         )}
 | |
|         {iconType !== 'app' && (
 | |
|           <DatasetInfo
 | |
|             expand={expand}
 | |
|             extraInfo={extraInfo && extraInfo(appSidebarExpand)}
 | |
|           />
 | |
|         )}
 | |
|       </div>
 | |
|       <div className='px-4'>
 | |
|         <div className={cn('mx-auto mt-1 h-[1px] bg-divider-subtle', !expand && 'w-6')} />
 | |
|       </div>
 | |
|       <nav
 | |
|         className={`
 | |
|           grow space-y-1
 | |
|           ${expand ? 'p-4' : 'px-2.5 py-4'}
 | |
|         `}
 | |
|       >
 | |
|         {navigation.map((item, index) => {
 | |
|           return (
 | |
|             <NavLink key={index} mode={appSidebarExpand} iconMap={{ selected: item.selectedIcon, normal: item.icon }} name={item.name} href={item.href} />
 | |
|           )
 | |
|         })}
 | |
|       </nav>
 | |
|       {
 | |
|         !isMobile && (
 | |
|           <div
 | |
|             className={`
 | |
|               shrink-0 py-3
 | |
|               ${expand ? 'px-6' : 'px-4'}
 | |
|             `}
 | |
|           >
 | |
|             <div
 | |
|               className='flex h-6 w-6 cursor-pointer items-center justify-center'
 | |
|               onClick={() => handleToggle(appSidebarExpand)}
 | |
|             >
 | |
|               {
 | |
|                 expand
 | |
|                   ? <RiLayoutRight2Line className='h-5 w-5 text-components-menu-item-text' />
 | |
|                   : <RiLayoutLeft2Line className='h-5 w-5 text-components-menu-item-text' />
 | |
|               }
 | |
|             </div>
 | |
|           </div>
 | |
|         )
 | |
|       }
 | |
|     </div>
 | |
|   )
 | |
| }
 | |
| 
 | |
| export default React.memo(AppDetailNav)
 |