aboutsummaryrefslogtreecommitdiff
path: root/apps/web/components/new/document-cards/tweet-preview.tsx
blob: 291bc18a77f609cf39b84a0fb9daf31a1d6d5f5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"use client"

import { Suspense } from "react"
import type { Tweet } from "react-tweet/api"
import {
	TweetContainer,
	TweetHeader,
	TweetBody,
	TweetMedia,
	enrichTweet,
	TweetSkeleton,
} from "react-tweet"
import { cn } from "@lib/utils"
import { dmSansClassName } from "@/lib/fonts"

export function TweetPreview({
	data,
	noBgColor,
}: {
	data: Tweet
	noBgColor?: boolean
}) {
	const parsedTweet = typeof data === "string" ? JSON.parse(data) : data
	const tweet = enrichTweet(parsedTweet)

	return (
		<div
			className={cn(
				"p-3 sm-tweet-theme w-full min-w-0",
				noBgColor
					? "bg-transparent rounded-none"
					: "bg-[#0B1017]! rounded-[18px]",
			)}
		>
			<Suspense fallback={<TweetSkeleton />}>
				<TweetContainer
					className={cn(
						"pb-0! my-0! bg-transparent! border-none! w-full! min-w-0!",
						dmSansClassName(),
					)}
				>
					<TweetHeader tweet={tweet} components={{}} />
					<TweetBody tweet={tweet} />
					{tweet.mediaDetails?.length ? (
						<TweetMedia tweet={tweet} components={{}} />
					) : null}
				</TweetContainer>
			</Suspense>
		</div>
	)
}