You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use client'
  2. import React, { useEffect, useState } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import { XMarkIcon } from '@heroicons/react/20/solid'
  5. import Loading from '@/app/components/base/loading'
  6. import s from './index.module.css'
  7. import cn from '@/utils/classnames'
  8. import type { NotionPage } from '@/models/common'
  9. import NotionIcon from '@/app/components/base/notion-icon'
  10. import { fetchNotionPagePreview } from '@/service/datasets'
  11. type IProps = {
  12. currentPage?: NotionPage
  13. hidePreview: () => void
  14. }
  15. const NotionPagePreview = ({
  16. currentPage,
  17. hidePreview,
  18. }: IProps) => {
  19. const { t } = useTranslation()
  20. const [previewContent, setPreviewContent] = useState('')
  21. const [loading, setLoading] = useState(true)
  22. const getPreviewContent = async () => {
  23. if (!currentPage)
  24. return
  25. try {
  26. const res = await fetchNotionPagePreview({
  27. workspaceID: currentPage.workspace_id,
  28. pageID: currentPage.page_id,
  29. pageType: currentPage.type,
  30. })
  31. setPreviewContent(res.content)
  32. setLoading(false)
  33. }
  34. catch { }
  35. }
  36. useEffect(() => {
  37. if (currentPage) {
  38. setLoading(true)
  39. getPreviewContent()
  40. }
  41. }, [currentPage])
  42. return (
  43. <div className={cn(s.filePreview, 'h-full')}>
  44. <div className={cn(s.previewHeader)}>
  45. <div className={cn(s.title, 'title-md-semi-bold')}>
  46. <span>{t('datasetCreation.stepOne.pagePreview')}</span>
  47. <div className='flex h-6 w-6 cursor-pointer items-center justify-center' onClick={hidePreview}>
  48. <XMarkIcon className='h-4 w-4'></XMarkIcon>
  49. </div>
  50. </div>
  51. <div className={cn(s.fileName, 'system-xs-medium')}>
  52. <NotionIcon
  53. className='mr-1 shrink-0'
  54. type='page'
  55. src={currentPage?.page_icon}
  56. />
  57. {currentPage?.page_name}
  58. </div>
  59. </div>
  60. <div className={cn(s.previewContent, 'body-md-regular')}>
  61. {loading && <Loading type='area' />}
  62. {!loading && (
  63. <div className={cn(s.fileContent, 'body-md-regular')}>{previewContent}</div>
  64. )}
  65. </div>
  66. </div>
  67. )
  68. }
  69. export default NotionPagePreview