|
1 | | -import * as React from 'react' |
| 1 | +import cs from 'classnames' |
2 | 2 | import dynamic from 'next/dynamic' |
3 | | -import Image from 'next/image' |
| 3 | +import Image from 'next/legacy/image' |
4 | 4 | import Link from 'next/link' |
5 | 5 | import { useRouter } from 'next/router' |
6 | | - |
7 | | -import cs from 'classnames' |
8 | | -import { PageBlock } from 'notion-types' |
| 6 | +import { type PageBlock } from 'notion-types' |
9 | 7 | import { formatDate, getBlockTitle, getPageProperty } from 'notion-utils' |
| 8 | +import * as React from 'react' |
10 | 9 | import BodyClassName from 'react-body-classname' |
11 | | -import { NotionRenderer } from 'react-notion-x' |
12 | | -import TweetEmbed from 'react-tweet-embed' |
| 10 | +import { |
| 11 | + type NotionComponents, |
| 12 | + NotionRenderer, |
| 13 | + useNotionContext |
| 14 | +} from 'react-notion-x' |
| 15 | +import { EmbeddedTweet, TweetNotFound, TweetSkeleton } from 'react-tweet' |
13 | 16 | import { useSearchParam } from 'react-use' |
14 | 17 |
|
| 18 | +import type * as types from '@/lib/types' |
15 | 19 | import * as config from '@/lib/config' |
16 | | -import * as types from '@/lib/types' |
17 | 20 | import { mapImageUrl } from '@/lib/map-image-url' |
18 | 21 | import { getCanonicalPageUrl, mapPageUrl } from '@/lib/map-page-url' |
19 | 22 | import { searchNotion } from '@/lib/search-notion' |
@@ -97,8 +100,15 @@ const Modal = dynamic( |
97 | 100 | } |
98 | 101 | ) |
99 | 102 |
|
100 | | -const Tweet = ({ id }: { id: string }) => { |
101 | | - return <TweetEmbed tweetId={id} /> |
| 103 | +function Tweet({ id }: { id: string }) { |
| 104 | + const { recordMap } = useNotionContext() |
| 105 | + const tweet = (recordMap as types.ExtendedTweetRecordMap)?.tweets?.[id] |
| 106 | + |
| 107 | + return ( |
| 108 | + <React.Suspense fallback={<TweetSkeleton />}> |
| 109 | + {tweet ? <EmbeddedTweet tweet={tweet} /> : <TweetNotFound />} |
| 110 | + </React.Suspense> |
| 111 | + ) |
102 | 112 | } |
103 | 113 |
|
104 | 114 | const propertyLastEditedTimeValue = ( |
@@ -142,18 +152,18 @@ const propertyTextValue = ( |
142 | 152 | return defaultFn() |
143 | 153 | } |
144 | 154 |
|
145 | | -export const NotionPage: React.FC<types.PageProps> = ({ |
| 155 | +export function NotionPage({ |
146 | 156 | site, |
147 | 157 | recordMap, |
148 | 158 | error, |
149 | 159 | pageId |
150 | | -}) => { |
| 160 | +}: types.PageProps) { |
151 | 161 | const router = useRouter() |
152 | 162 | const lite = useSearchParam('lite') |
153 | 163 |
|
154 | | - const components = React.useMemo( |
| 164 | + const components = React.useMemo<Partial<NotionComponents>>( |
155 | 165 | () => ({ |
156 | | - nextImage: Image, |
| 166 | + nextLegacyImage: Image, |
157 | 167 | nextLink: Link, |
158 | 168 | Code, |
159 | 169 | Collection, |
|
0 commit comments