'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' import { useDataSourceStore } from '../data-source/store' 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() const dataSourceStore = useDataSourceStore() useEffect(() => { const { currentCredentialId } = dataSourceStore.getState() getOnlineDocumentContent({ workspaceID: currentPage.workspace_id, pageID: currentPage.page_id, pageType: currentPage.type, pipelineId: pipelineId || '', datasourceNodeId, credentialId: currentCredentialId, }, { onSuccess(data) { setContent(data.content) }, onError(error) { Toast.notify({ type: 'error', message: error.message, }) }, }) }, [currentPage.page_id]) return (
{t('datasetPipeline.addDocuments.stepOne.preview')}
{currentPage?.page_name}
{currentPage.type} ยท {`${formatNumberAbbreviated(content.length)} ${t('datasetPipeline.addDocuments.characters')}`}
{isPending && (
)} {!isPending && content && (
)}
) } export default OnlineDocumentPreview