'use client' import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import type { NotionPage } from '@/models/common' import { RiCloseLine } from '@remixicon/react' import { formatNumberAbbreviated } from '@/utils/format' import Loading from './loading' import { Notion } from '@/app/components/base/icons/src/public/common' import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail' import { usePreviewOnlineDocument } from '@/service/use-pipeline' import Toast from '@/app/components/base/toast' import { Markdown } from '@/app/components/base/markdown' type OnlineDocumentPreviewProps = { currentPage: NotionPage datasourceNodeId: string hidePreview: () => void } const OnlineDocumentPreview = ({ currentPage, datasourceNodeId, hidePreview, }: OnlineDocumentPreviewProps) => { const { t } = useTranslation() const [content, setContent] = useState('') const pipelineId = useDatasetDetailContextWithSelector(state => state.dataset?.pipeline_id) const { mutateAsync: getOnlineDocumentContent, isPending } = usePreviewOnlineDocument() useEffect(() => { getOnlineDocumentContent({ workspaceID: currentPage.workspace_id, pageID: currentPage.page_id, pageType: currentPage.type, pipelineId: pipelineId || '', datasourceNodeId, }, { onSuccess(data) { setContent(data.content) }, onError(error) { Toast.notify({ type: 'error', message: error.message, }) }, }) // eslint-disable-next-line react-hooks/exhaustive-deps }, []) return (
{t('datasetPipeline.addDocuments.stepOne.preview')}
{currentPage?.page_name}
{currentPage.type} ยท {`${formatNumberAbbreviated(content.length)} ${t('datasetPipeline.addDocuments.characters')}`}
{isPending && (
)} {!isPending && content && (
)}
) } export default OnlineDocumentPreview