1
- import { Flex , Heading , Text , TextField } from "@radix-ui/themes" ;
2
- import { startTransition } from "react" ;
1
+ import { Flex , Heading , Skeleton , Text , TextField } from "@radix-ui/themes" ;
2
+ import { startTransition , useEffect , useState } from "react" ;
3
3
import { OgImage } from "../OgImage" ;
4
4
import { useElementsStore } from "../../stores/elementsStore" ;
5
5
import { usePreviewControls } from "../../lib/hooks/usePreviewControls" ;
6
+ import { renderToImg } from "../../lib/export" ;
6
7
7
8
interface PreviewProps {
8
9
dynamicTexts : Record < string , string > ;
@@ -12,6 +13,15 @@ interface PreviewProps {
12
13
export function Preview ( { dynamicTexts, setDynamicTexts } : PreviewProps ) {
13
14
const { preview, PreviewControls } = usePreviewControls ( ) ;
14
15
const elements = useElementsStore ( ( state ) => state . elements ) ;
16
+ const [ src , setSrc ] = useState < string | undefined > ( ) ;
17
+
18
+ useEffect ( ( ) => {
19
+ async function render ( ) {
20
+ setSrc ( await renderToImg ( elements , dynamicTexts ) ) ;
21
+ }
22
+
23
+ void render ( ) ;
24
+ } , [ elements , dynamicTexts ] ) ;
15
25
16
26
return (
17
27
< Flex direction = "column" gap = "4" >
@@ -21,13 +31,9 @@ export function Preview({ dynamicTexts, setDynamicTexts }: PreviewProps) {
21
31
< Flex gap = "6" justify = "between" align = "start" minHeight = "353px" >
22
32
< Flex direction = "column" gap = "2" >
23
33
< PreviewControls />
24
- < OgImage
25
- client
26
- dynamicTexts = { dynamicTexts }
27
- elements = { elements }
28
- preview = { preview }
29
- size = "medium"
30
- />
34
+ < OgImage preview = { preview } size = "medium" src = { src } >
35
+ { src ? null : < Skeleton height = "10%" width = "60%" /> }
36
+ </ OgImage >
31
37
</ Flex >
32
38
< Flex direction = "column" flexGrow = "1" gap = "4" mt = "7" >
33
39
{ Object . keys ( dynamicTexts ) . length === 0 ? (
0 commit comments