feat: improve tweet embedding using react-tweet

This commit is contained in:
Travis Fischer
2024-11-10 16:07:25 +07:00
parent 172bd84f83
commit e2017fdd3e
7 changed files with 165 additions and 87 deletions

View File

@@ -7,8 +7,12 @@ import { type PageBlock } from 'notion-types'
import { formatDate, getBlockTitle, getPageProperty } from 'notion-utils'
import * as React from 'react'
import BodyClassName from 'react-body-classname'
import { type NotionComponents, NotionRenderer } from 'react-notion-x'
import TweetEmbed from 'react-tweet-embed'
import {
type NotionComponents,
NotionRenderer,
useNotionContext
} from 'react-notion-x'
import { EmbeddedTweet, TweetNotFound, TweetSkeleton } from 'react-tweet'
import { useSearchParam } from 'react-use'
import type * as types from '@/lib/types'
@@ -97,7 +101,14 @@ const Modal = dynamic(
)
function Tweet({ id }: { id: string }) {
return <TweetEmbed tweetId={id} />
const { recordMap } = useNotionContext()
const tweet = (recordMap as types.ExtendedTweetRecordMap)?.tweets?.[id]
return (
<React.Suspense fallback={<TweetSkeleton />}>
{tweet ? <EmbeddedTweet tweet={tweet} /> : <TweetNotFound />}
</React.Suspense>
)
}
const propertyLastEditedTimeValue = (