2023-06-16 21:47:51 +08:00
|
|
|
'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'
|
2024-07-09 15:05:40 +08:00
|
|
|
import cn from '@/utils/classnames'
|
2023-08-28 19:48:53 +08:00
|
|
|
import type { NotionPage } from '@/models/common'
|
2023-06-16 21:47:51 +08:00
|
|
|
import NotionIcon from '@/app/components/base/notion-icon'
|
|
|
|
import { fetchNotionPagePreview } from '@/service/datasets'
|
|
|
|
|
|
|
|
type IProps = {
|
2023-08-28 19:48:53 +08:00
|
|
|
currentPage?: NotionPage
|
2023-06-16 21:47:51 +08:00
|
|
|
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)
|
|
|
|
}
|
2024-07-09 15:05:40 +08:00
|
|
|
catch { }
|
2023-06-16 21:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (currentPage) {
|
|
|
|
setLoading(true)
|
|
|
|
getPreviewContent()
|
|
|
|
}
|
|
|
|
}, [currentPage])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={cn(s.filePreview)}>
|
|
|
|
<div className={cn(s.previewHeader)}>
|
|
|
|
<div className={cn(s.title)}>
|
|
|
|
<span>{t('datasetCreation.stepOne.pagePreview')}</span>
|
|
|
|
<div className='flex items-center justify-center w-6 h-6 cursor-pointer' onClick={hidePreview}>
|
|
|
|
<XMarkIcon className='h-4 w-4'></XMarkIcon>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={cn(s.fileName)}>
|
|
|
|
<NotionIcon
|
|
|
|
className='shrink-0 mr-1'
|
|
|
|
type='page'
|
|
|
|
src={currentPage?.page_icon}
|
|
|
|
/>
|
|
|
|
{currentPage?.page_name}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={cn(s.previewContent)}>
|
2024-07-09 15:05:40 +08:00
|
|
|
{loading && <div className={cn(s.loading)} />}
|
2023-06-16 21:47:51 +08:00
|
|
|
{!loading && (
|
|
|
|
<div className={cn(s.fileContent)}>{previewContent}</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default NotionPagePreview
|