index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. 'use client'
  2. import { useCallback, useEffect } from 'react'
  3. import Link from 'next/link'
  4. import { useBoolean } from 'ahooks'
  5. import { useSelectedLayoutSegment } from 'next/navigation'
  6. import { Bars3Icon } from '@heroicons/react/20/solid'
  7. import { useContextSelector } from 'use-context-selector'
  8. import HeaderBillingBtn from '../billing/header-billing-btn'
  9. import AccountDropdown from './account-dropdown'
  10. import AppNav from './app-nav'
  11. import DatasetNav from './dataset-nav'
  12. import DatabaseNav from './database-nav'
  13. import EnvNav from './env-nav'
  14. import ExploreNav from './explore-nav'
  15. import ToolsNav from './tools-nav'
  16. import GithubStar from './github-star'
  17. import LicenseNav from './license-env'
  18. import { WorkspaceProvider } from '@/context/workspace-context'
  19. import AppContext, { useAppContext } from '@/context/app-context'
  20. import LogoSite from '@/app/components/base/logo/logo-site'
  21. import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
  22. import { useProviderContext } from '@/context/provider-context'
  23. import { useModalContext } from '@/context/modal-context'
  24. import { LicenseStatus } from '@/types/feature'
  25. const navClassName = `
  26. flex items-center relative mr-0 sm:mr-3 px-3 h-8 rounded-xl
  27. font-medium text-sm
  28. cursor-pointer
  29. `
  30. const Header = () => {
  31. const { isCurrentWorkspaceEditor, isCurrentWorkspaceDatasetOperator } = useAppContext()
  32. const systemFeatures = useContextSelector(AppContext, v => v.systemFeatures)
  33. const selectedSegment = useSelectedLayoutSegment()
  34. const media = useBreakpoints()
  35. const isMobile = media === MediaType.mobile
  36. const [isShowNavMenu, { toggle, setFalse: hideNavMenu }] = useBoolean(false)
  37. const { enableBilling, plan } = useProviderContext()
  38. const { setShowPricingModal, setShowAccountSettingModal } = useModalContext()
  39. const isFreePlan = plan.type === 'sandbox'
  40. const handlePlanClick = useCallback(() => {
  41. if (isFreePlan)
  42. setShowPricingModal()
  43. else
  44. setShowAccountSettingModal({ payload: 'billing' })
  45. }, [isFreePlan, setShowAccountSettingModal, setShowPricingModal])
  46. useEffect(() => {
  47. hideNavMenu()
  48. // eslint-disable-next-line react-hooks/exhaustive-deps
  49. }, [selectedSegment])
  50. return (
  51. //首页顶部导航栏nav 云脑
  52. <div className='flex flex-1 items-center justify-between px-4'>
  53. <div className='flex items-center'>
  54. {isMobile && <div
  55. className='flex items-center justify-center h-8 w-8 cursor-pointer'
  56. onClick={toggle}
  57. >
  58. <Bars3Icon className="h-4 w-4 text-gray-500" />
  59. </div>}
  60. {!isMobile && <>
  61. <Link href="/apps" className='flex items-center mr-4'>
  62. <LogoSite className='object-contain' />
  63. </Link>
  64. {systemFeatures.license.status === LicenseStatus.NONE && <GithubStar />}
  65. </>}
  66. </div>
  67. {isMobile && (
  68. <div className='flex'>
  69. <Link href="/apps" className='flex items-center mr-4'>
  70. <LogoSite />
  71. </Link>
  72. {systemFeatures.license.status === LicenseStatus.NONE && <GithubStar />}
  73. </div>
  74. )}
  75. {!isMobile && (
  76. <div className='flex items-center'>
  77. {/* {!isCurrentWorkspaceDatasetOperator && <ExploreNav className={navClassName} />} */}
  78. {/* 工作室nav */}
  79. {!isCurrentWorkspaceDatasetOperator && <AppNav />}
  80. {(isCurrentWorkspaceEditor || isCurrentWorkspaceDatasetOperator) && <DatabaseNav />}
  81. {(isCurrentWorkspaceEditor || isCurrentWorkspaceDatasetOperator) && <DatasetNav />}
  82. {/* {!isCurrentWorkspaceDatasetOperator && <ToolsNav className={navClassName} />} */}
  83. </div>
  84. )}
  85. <div className='flex items-center flex-shrink-0'>
  86. <LicenseNav />
  87. <EnvNav />
  88. {enableBilling && (
  89. <div className='mr-3 select-none'>
  90. <HeaderBillingBtn onClick={handlePlanClick} />
  91. </div>
  92. )}
  93. <WorkspaceProvider>
  94. <AccountDropdown isMobile={isMobile} />
  95. </WorkspaceProvider>
  96. </div>
  97. {(isMobile && isShowNavMenu) && (
  98. <div className='w-full flex flex-col p-2 gap-y-1'>
  99. {/* {!isCurrentWorkspaceDatasetOperator && <ExploreNav className={navClassName} />} */}
  100. {!isCurrentWorkspaceDatasetOperator && <AppNav />}
  101. {(isCurrentWorkspaceEditor || isCurrentWorkspaceDatasetOperator) && <DatabaseNav />}
  102. {(isCurrentWorkspaceEditor || isCurrentWorkspaceDatasetOperator) && <DatasetNav />}
  103. {/* {!isCurrentWorkspaceDatasetOperator && <ToolsNav className={navClassName} />} */}
  104. </div>
  105. )}
  106. </div>
  107. )
  108. }
  109. export default Header