'use client' import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { XMarkIcon } from '@heroicons/react/20/solid' import s from './index.module.css' import cn from '@/utils/classnames' import type { NotionPage } from '@/models/common' import NotionIcon from '@/app/components/base/notion-icon' import { fetchNotionPagePreview } from '@/service/datasets' type IProps = { currentPage?: NotionPage hidePreview: () => void } const NotionPagePreview = ({ currentPage, hidePreview, }: IProps) => { const { t } = useTranslation() const [previewContent, setPreviewContent] = useState('') const [loading, setLoading] = useState(true) const getPreviewContent = async () => { if (!currentPage) return try { const res = await fetchNotionPagePreview({ workspaceID: currentPage.workspace_id, pageID: currentPage.page_id, pageType: currentPage.type, }) setPreviewContent(res.content) setLoading(false) } catch { } } useEffect(() => { if (currentPage) { setLoading(true) getPreviewContent() } }, [currentPage]) return (
{t('datasetCreation.stepOne.pagePreview')}
{currentPage?.page_name}
{loading &&
} {!loading && (
{previewContent}
)}
) } export default NotionPagePreview