Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

index.tsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import React, { useEffect } from 'react'
  2. import { useShallow } from 'zustand/react/shallow'
  3. import { RiLayoutLeft2Line, RiLayoutRight2Line } from '@remixicon/react'
  4. import NavLink from './navLink'
  5. import type { NavIcon } from './navLink'
  6. import AppBasic from './basic'
  7. import AppInfo from './app-info'
  8. import DatasetInfo from './dataset-info'
  9. import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
  10. import { useStore as useAppStore } from '@/app/components/app/store'
  11. import cn from '@/utils/classnames'
  12. export type IAppDetailNavProps = {
  13. iconType?: 'app' | 'dataset' | 'notion'
  14. title: string
  15. desc: string
  16. isExternal?: boolean
  17. icon: string
  18. icon_background: string | null
  19. navigation: Array<{
  20. name: string
  21. href: string
  22. icon: NavIcon
  23. selectedIcon: NavIcon
  24. }>
  25. extraInfo?: (modeState: string) => React.ReactNode
  26. }
  27. const AppDetailNav = ({ title, desc, isExternal, icon, icon_background, navigation, extraInfo, iconType = 'app' }: IAppDetailNavProps) => {
  28. const { appSidebarExpand, setAppSiderbarExpand } = useAppStore(useShallow(state => ({
  29. appSidebarExpand: state.appSidebarExpand,
  30. setAppSiderbarExpand: state.setAppSiderbarExpand,
  31. })))
  32. const media = useBreakpoints()
  33. const isMobile = media === MediaType.mobile
  34. const expand = appSidebarExpand === 'expand'
  35. const handleToggle = (state: string) => {
  36. setAppSiderbarExpand(state === 'expand' ? 'collapse' : 'expand')
  37. }
  38. useEffect(() => {
  39. if (appSidebarExpand) {
  40. localStorage.setItem('app-detail-collapse-or-expand', appSidebarExpand)
  41. setAppSiderbarExpand(appSidebarExpand)
  42. }
  43. }, [appSidebarExpand, setAppSiderbarExpand])
  44. return (
  45. <div
  46. className={`
  47. flex shrink-0 flex-col border-r border-divider-burn bg-background-default-subtle transition-all
  48. ${expand ? 'w-[216px]' : 'w-14'}
  49. `}
  50. >
  51. <div
  52. className={`
  53. shrink-0
  54. ${expand ? 'p-2' : 'p-1'}
  55. `}
  56. >
  57. {iconType === 'app' && (
  58. <AppInfo expand={expand} />
  59. )}
  60. {iconType === 'dataset' && (
  61. <DatasetInfo
  62. name={title}
  63. description={desc}
  64. isExternal={isExternal}
  65. expand={expand}
  66. extraInfo={extraInfo && extraInfo(appSidebarExpand)}
  67. />
  68. )}
  69. {!['app', 'dataset'].includes(iconType) && (
  70. <AppBasic
  71. mode={appSidebarExpand}
  72. iconType={iconType}
  73. icon={icon}
  74. icon_background={icon_background}
  75. name={title}
  76. type={desc}
  77. isExternal={isExternal}
  78. />
  79. )}
  80. </div>
  81. <div className='px-4'>
  82. <div className={cn('mx-auto mt-1 h-[1px] bg-divider-subtle', !expand && 'w-6')} />
  83. </div>
  84. <nav
  85. className={`
  86. grow space-y-1
  87. ${expand ? 'p-4' : 'px-2.5 py-4'}
  88. `}
  89. >
  90. {navigation.map((item, index) => {
  91. return (
  92. <NavLink key={index} mode={appSidebarExpand} iconMap={{ selected: item.selectedIcon, normal: item.icon }} name={item.name} href={item.href} />
  93. )
  94. })}
  95. </nav>
  96. {
  97. !isMobile && (
  98. <div
  99. className={`
  100. shrink-0 py-3
  101. ${expand ? 'px-6' : 'px-4'}
  102. `}
  103. >
  104. <div
  105. className='flex h-6 w-6 cursor-pointer items-center justify-center'
  106. onClick={() => handleToggle(appSidebarExpand)}
  107. >
  108. {
  109. expand
  110. ? <RiLayoutRight2Line className='h-5 w-5 text-components-menu-item-text' />
  111. : <RiLayoutLeft2Line className='h-5 w-5 text-components-menu-item-text' />
  112. }
  113. </div>
  114. </div>
  115. )
  116. }
  117. </div>
  118. )
  119. }
  120. export default React.memo(AppDetailNav)