Container.tsx 1.6 KB

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