-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathembeds.tsx
60 lines (59 loc) · 1.79 KB
/
embeds.tsx
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
52
53
54
55
56
57
58
59
60
import {
Embed,
hasFullSizedImage,
isImageEmbed,
isVideoEmbed,
} from "@mod-protocol/core";
import { isFarcasterUrlEmbed } from "@mod-protocol/farcaster";
import { Cross1Icon } from "@radix-ui/react-icons";
import { Button } from "components/ui/button";
import { Skeleton } from "components/ui/skeleton";
import { VideoRenderer } from "../renderers/video";
export const EmbedsEditor = ({
embeds,
setEmbeds,
RichEmbed,
}: {
embeds: Embed[];
setEmbeds: (e: Embed[]) => void;
RichEmbed: (props: { embed: Embed }) => JSX.Element;
}) => {
return (
<>
{embeds.map((embed, i) => (
<div key={i} className="relative">
<Button
className="rounded-full text-white dark:text-black hover:text-gray-300 absolute -top-4 -left-4 border-white dark:border-black border z-50"
size="icon"
type="button"
onClick={() => {
setEmbeds(embeds.filter((item, j) => j !== i));
}}
>
<Cross1Icon />
</Button>
{isFarcasterUrlEmbed(embed) && isImageEmbed(embed) ? (
<div className="border rounded mt-2" key={i}>
<img
src={embed.url}
alt={embed.metadata?.alt}
className="rounded"
style={{ width: "100%" }}
width={300}
height={100}
/>
</div>
) : isFarcasterUrlEmbed(embed) && isVideoEmbed(embed) ? (
<VideoRenderer videoSrc={embed.url} />
) : embed.status === "loading" ? (
<Skeleton className="h-[100px] w-full items-center flex justify-center">
Loading...
</Skeleton>
) : (
<RichEmbed embed={embed} />
)}
</div>
))}
</>
);
};