Container.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use client'
  2. // Libraries
  3. import { useRef } 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 TabSliderNew from '@/app/components/base/tab-slider-new'
  12. // Services
  13. import { fetchDatasetApiBaseUrl } from '@/service/datasets'
  14. // Hooks
  15. import { useTabSearchParams } from '@/hooks/use-tab-searchparams'
  16. const Container = () => {
  17. const { t } = useTranslation()
  18. const options = [
  19. { value: 'dataset', text: t('dataset.datasets') },
  20. { value: 'api', text: t('dataset.datasetsApi') },
  21. ]
  22. const [activeTab, setActiveTab] = useTabSearchParams({
  23. defaultTab: 'dataset',
  24. })
  25. const containerRef = useRef<HTMLDivElement>(null)
  26. const { data } = useSWR(activeTab === 'dataset' ? null : '/datasets/api-base-info', fetchDatasetApiBaseUrl)
  27. return (
  28. <div ref={containerRef} className='grow relative flex flex-col bg-gray-100 overflow-y-auto'>
  29. <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'>
  30. <TabSliderNew
  31. value={activeTab}
  32. onChange={newActiveTab => setActiveTab(newActiveTab)}
  33. options={options}
  34. />
  35. {activeTab === 'api' && data && <ApiServer apiBaseUrl={data.api_base_url || ''} />}
  36. </div>
  37. {activeTab === 'dataset' && (
  38. <>
  39. <Datasets containerRef={containerRef} />
  40. <DatasetFooter />
  41. </>
  42. )}
  43. {activeTab === 'api' && data && <Doc apiBaseUrl={data.api_base_url || ''} />}
  44. </div>
  45. )
  46. }
  47. export default Container