diff --git a/web/src/components/MemoContent/Link.tsx b/web/src/components/MemoContent/Link.tsx index 1acd8726..5ef9d6b0 100644 --- a/web/src/components/MemoContent/Link.tsx +++ b/web/src/components/MemoContent/Link.tsx @@ -1,18 +1,92 @@ +import { Tooltip, Card, AspectRatio, Box } from "@mui/joy"; +import { Link as MLink } from "@mui/joy"; +import { useEffect, useState } from "react"; +import { linkServiceClient } from "@/grpcweb"; +import useResponsiveWidth from "@/hooks/useResponsiveWidth"; +import { LinkMetadata } from "@/types/proto/api/v2/link_service"; + interface Props { url: string; text?: string; } const Link: React.FC = ({ text, url }: Props) => { + const [linkMetadata, setLinkMetadata] = useState(); + const { md } = useResponsiveWidth(); + + const fetchUrlMetadata = async () => { + try { + const response = await linkServiceClient.getLinkMetadata({ link: url }, {}); + setLinkMetadata(response.metadata); + } catch (error) { + console.error("Error fetching URL metadata:", error); + return null; + } + }; + + useEffect(() => { + fetchUrlMetadata(); + }, [url]); + return ( - - {text || url} - + <> + {md ? ( +
+ + {linkMetadata?.image ? ( + + + + {linkMetadata?.title} + +
+
+
+

{linkMetadata?.title}

+ {linkMetadata?.description &&

{linkMetadata?.description}

} +
+
+
+
+
+ ) : ( + +
+
+
+

{linkMetadata?.title}

+

No Preview

+
+
+
+
+ )} + + } + > + + {url || text} + +
+
+ ) : ( + + {url || text} + + )} + ); }; diff --git a/web/src/grpcweb.ts b/web/src/grpcweb.ts index a3613ce1..bfbaafe6 100644 --- a/web/src/grpcweb.ts +++ b/web/src/grpcweb.ts @@ -2,6 +2,7 @@ import { createChannel, createClientFactory, FetchTransport } from "nice-grpc-we import { ActivityServiceDefinition } from "./types/proto/api/v2/activity_service"; import { AuthServiceDefinition } from "./types/proto/api/v2/auth_service"; import { InboxServiceDefinition } from "./types/proto/api/v2/inbox_service"; +import { LinkServiceDefinition } from "./types/proto/api/v2/link_service"; import { MemoServiceDefinition } from "./types/proto/api/v2/memo_service"; import { ResourceServiceDefinition } from "./types/proto/api/v2/resource_service"; import { TagServiceDefinition } from "./types/proto/api/v2/tag_service"; @@ -38,3 +39,5 @@ export const inboxServiceClient = clientFactory.create(InboxServiceDefinition, c export const activityServiceClient = clientFactory.create(ActivityServiceDefinition, channel); export const webhookServiceClient = clientFactory.create(WebhookServiceDefinition, channel); + +export const linkServiceClient = clientFactory.create(LinkServiceDefinition, channel);