57 lines
1.6 KiB
TypeScript
Raw Normal View History

'use client'
2023-09-27 21:06:52 -05:00
// Libraries
import { useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import useSWR from 'swr'
2023-09-27 21:06:52 -05:00
// Components
import Datasets from './Datasets'
import DatasetFooter from './DatasetFooter'
import ApiServer from './ApiServer'
import Doc from './Doc'
import TabSlider from '@/app/components/base/tab-slider'
2023-09-27 21:06:52 -05:00
// Services
import { fetchDatasetApiBaseUrl } from '@/service/datasets'
const Container = () => {
const { t } = useTranslation()
2023-09-27 21:06:52 -05:00
const options = [
2023-09-27 21:06:52 -05:00
{ value: 'dataset', text: t('dataset.datasets') },
{ value: 'api', text: t('dataset.datasetsApi') },
]
2023-09-27 21:06:52 -05:00
const [activeTab, setActiveTab] = useState('dataset')
const containerRef = useRef<HTMLDivElement>(null)
const { data } = useSWR(activeTab === 'dataset' ? null : '/datasets/api-base-info', fetchDatasetApiBaseUrl)
return (
<div ref={containerRef} className='grow relative flex flex-col bg-gray-100 overflow-y-auto'>
<div className='sticky top-0 flex justify-between pt-4 px-12 pb-2 h-14 bg-gray-100 z-10'>
<TabSlider
value={activeTab}
onChange={newActiveTab => setActiveTab(newActiveTab)}
options={options}
/>
2023-09-27 21:06:52 -05:00
{activeTab === 'api' && data && <ApiServer apiBaseUrl={data.api_base_url || ''} />}
</div>
2023-09-27 21:06:52 -05:00
{activeTab === 'dataset'
? (
<>
<Datasets containerRef={containerRef} />
<DatasetFooter />
2023-09-27 21:06:52 -05:00
</>
)
2023-09-27 21:06:52 -05:00
: (
activeTab === 'api' && data && <Doc apiBaseUrl={data.api_base_url || ''} />
)}
</div>
2023-09-27 21:06:52 -05:00
)
}
export default Container