Container.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 leading-[56px] bg-gray-100 z-10 flex-wrap gap-y-2'>
  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. <Datasets containerRef={containerRef} />
  36. <DatasetFooter />
  37. </>
  38. )}
  39. {activeTab === 'api' && data && <Doc apiBaseUrl={data.api_base_url || ''} />}
  40. </div>
  41. )
  42. }
  43. export default Container