Container.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use client'
  2. import { useRef, useState } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import useSWR from 'swr'
  5. import Datasets from './Datasets'
  6. import DatasetFooter from './DatasetFooter'
  7. import ApiServer from './ApiServer'
  8. import Doc from './Doc'
  9. import TabSlider from '@/app/components/base/tab-slider'
  10. import { fetchDatasetApiBaseUrl } from '@/service/datasets'
  11. const Container = () => {
  12. const { t } = useTranslation()
  13. const options = [
  14. {
  15. value: 'dataset',
  16. text: t('dataset.datasets'),
  17. },
  18. {
  19. value: 'api',
  20. text: t('dataset.datasetsApi'),
  21. },
  22. ]
  23. const [activeTab, setActiveTab] = useState('dataset')
  24. const containerRef = useRef<HTMLDivElement>(null)
  25. const { data } = useSWR(activeTab === 'dataset' ? null : '/datasets/api-base-info', fetchDatasetApiBaseUrl)
  26. return (
  27. <div ref={containerRef} className='grow relative flex flex-col bg-gray-100 overflow-y-auto'>
  28. <div className='sticky top-0 flex justify-between pt-4 px-12 pb-2 h-14 bg-gray-100 z-10'>
  29. <TabSlider
  30. value={activeTab}
  31. onChange={newActiveTab => setActiveTab(newActiveTab)}
  32. options={options}
  33. />
  34. {
  35. activeTab === 'api' && (
  36. <ApiServer apiBaseUrl={data?.api_base_url || ''} />
  37. )
  38. }
  39. </div>
  40. {
  41. activeTab === 'dataset' && (
  42. <div className=''>
  43. <Datasets containerRef={containerRef}/>
  44. <DatasetFooter />
  45. </div>
  46. )
  47. }
  48. {
  49. activeTab === 'api' && (
  50. <Doc apiBaseUrl={data?.api_base_url || ''} />
  51. )
  52. }
  53. </div>
  54. )
  55. }
  56. export default Container