You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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
  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 = ({
  28. title,
  29. desc,
  30. isExternal,
  31. icon,
  32. icon_background,
  33. navigation,
  34. extraInfo,
  35. iconType = 'app',
  36. }: IAppDetailNavProps) => {
  37. const { appSidebarExpand, setAppSidebarExpand } = useAppStore(useShallow(state => ({
  38. appSidebarExpand: state.appSidebarExpand,
  39. setAppSidebarExpand: state.setAppSidebarExpand,
  40. })))
  41. const media = useBreakpoints()
  42. const isMobile = media === MediaType.mobile
  43. const expand = appSidebarExpand === 'expand'
  44. const handleToggle = (state: string) => {
  45. setAppSidebarExpand(state === 'expand' ? 'collapse' : 'expand')
  46. }
  47. useEffect(() => {
  48. if (appSidebarExpand) {
  49. localStorage.setItem('app-detail-collapse-or-expand', appSidebarExpand)
  50. setAppSidebarExpand(appSidebarExpand)
  51. }
  52. }, [appSidebarExpand, setAppSidebarExpand])
  53. return (
  54. <div
  55. className={`
  56. flex shrink-0 flex-col border-r border-divider-burn bg-background-default-subtle transition-all
  57. ${expand ? 'w-[216px]' : 'w-14'}
  58. `}
  59. >
  60. <div
  61. className={`
  62. shrink-0
  63. ${expand ? 'p-2' : 'p-1'}
  64. `}
  65. >
  66. {iconType === 'app' && (
  67. <AppInfo expand={expand} />
  68. )}
  69. {iconType === 'dataset' && (
  70. <DatasetInfo
  71. name={title}
  72. description={desc}
  73. isExternal={isExternal}
  74. expand={expand}
  75. extraInfo={extraInfo && extraInfo(appSidebarExpand)}
  76. />
  77. )}
  78. {!['app', 'dataset'].includes(iconType) && (
  79. <AppBasic
  80. mode={appSidebarExpand}
  81. iconType={iconType}
  82. icon={icon}
  83. icon_background={icon_background}
  84. name={title}
  85. type={desc}
  86. isExternal={isExternal}
  87. />
  88. )}
  89. </div>
  90. <div className='px-4'>
  91. <div className={cn('mx-auto mt-1 h-[1px] bg-divider-subtle', !expand && 'w-6')} />
  92. </div>
  93. <nav
  94. className={`
  95. grow space-y-1
  96. ${expand ? 'p-4' : 'px-2.5 py-4'}
  97. `}
  98. >
  99. {navigation.map((item, index) => {
  100. return (
  101. <NavLink key={index} mode={appSidebarExpand} iconMap={{ selected: item.selectedIcon, normal: item.icon }} name={item.name} href={item.href} />
  102. )
  103. })}
  104. </nav>
  105. {
  106. !isMobile && (
  107. <div
  108. className={`
  109. shrink-0 py-3
  110. ${expand ? 'px-6' : 'px-4'}
  111. `}
  112. >
  113. <div
  114. className='flex h-6 w-6 cursor-pointer items-center justify-center'
  115. onClick={() => handleToggle(appSidebarExpand)}
  116. >
  117. {
  118. expand
  119. ? <RiLayoutRight2Line className='h-5 w-5 text-components-menu-item-text' />
  120. : <RiLayoutLeft2Line className='h-5 w-5 text-components-menu-item-text' />
  121. }
  122. </div>
  123. </div>
  124. )
  125. }
  126. </div>
  127. )
  128. }
  129. export default React.memo(AppDetailNav)