'use client' import type { FC } from 'react' import React, { useMemo, useState } from 'react' import useSWR from 'swr' import { useTranslation } from 'react-i18next' import { useRouter } from 'next/navigation' import { debounce, omit } from 'lodash-es' // import Link from 'next/link' import { PlusIcon } from '@heroicons/react/24/solid' import List from './list' import s from './style.module.css' import Loading from '@/app/components/base/loading' import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' import Pagination from '@/app/components/base/pagination' import { get } from '@/service/base' import { fetchDocuments } from '@/service/datasets' // Custom page count is not currently supported. const limit = 15 const FolderPlusIcon: FC<{ className?: string }> = ({ className }) => { return } const ThreeDotsIcon: FC<{ className?: string }> = ({ className }) => { return } const NotionIcon: FC<{ className?: string }> = ({ className }) => { return } const EmptyElement: FC<{ onClick: () => void; type?: 'upload' | 'sync' }> = ({ onClick, type = 'upload' }) => { const { t } = useTranslation() return
{type === 'upload' ? : }
{t('datasetDocuments.list.empty.title')}
{t(`datasetDocuments.list.empty.${type}.tip`)}
{type === 'upload' && }
} type IDocumentsProps = { datasetId: string } export const fetcher = (url: string) => get(url, {}, {}) const Documents: FC = ({ datasetId }) => { const { t } = useTranslation() const [searchValue, setSearchValue] = useState('') const [currPage, setCurrPage] = React.useState(0) const router = useRouter() const query = useMemo(() => { return { page: currPage + 1, limit, keyword: searchValue } }, [searchValue, currPage]) const { data: documentsRes, error, mutate } = useSWR({ action: 'fetchDocuments', datasetId, params: query, }, apiParams => fetchDocuments(omit(apiParams, 'action'))) const total = documentsRes?.total || 0 const routeToDocCreate = () => { router.push(`/datasets/${datasetId}/documents/create`) } router.prefetch(`/datasets/${datasetId}/documents/create`) const isLoading = !documentsRes && !error return (

{t('datasetDocuments.list.title')}

{t('datasetDocuments.list.desc')}

{isLoading ? : total > 0 ? : } {/* Show Pagination only if the total is more than the limit */} {(total && total > limit) ? : null}
) } export default Documents