diff --git a/web/src/components/MemoContent/Link.tsx b/web/src/components/MemoContent/Link.tsx index 9825ff66..3678f6e8 100644 --- a/web/src/components/MemoContent/Link.tsx +++ b/web/src/components/MemoContent/Link.tsx @@ -1,5 +1,5 @@ import { Link as MLink, Tooltip } from "@mui/joy"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import { linkServiceClient } from "@/grpcweb"; import { LinkMetadata } from "@/types/proto/api/v2/link_service"; @@ -18,43 +18,48 @@ const getFaviconWithGoogleS2 = (url: string) => { }; const Link: React.FC = ({ text, url }: Props) => { + const [initialized, setInitialized] = useState(false); + const [showTooltip, setShowTooltip] = useState(false); const [linkMetadata, setLinkMetadata] = useState(); - useEffect(() => { - (async () => { + const handleMouseEnter = async () => { + if (!initialized) { try { const { linkMetadata } = await linkServiceClient.getLinkMetadata({ link: url }, {}); setLinkMetadata(linkMetadata); } catch (error) { console.error("Error fetching URL metadata:", error); } - })(); - }, [url]); + setInitialized(true); + } + setTimeout(() => setShowTooltip(true), 0); + }; - return linkMetadata ? ( + return ( - - {linkMetadata?.title} -

{linkMetadata?.title}

-
- {linkMetadata.description && ( -

{linkMetadata.description}

- )} - + linkMetadata && ( +
+
+ {linkMetadata?.title} +

{linkMetadata?.title}

+
+ {linkMetadata.description && ( +

{linkMetadata.description}

+ )} +
+ ) } + open={showTooltip} arrow > - {text || url} + setShowTooltip(false)}> + {text || url} +
- ) : ( - - {text || url} - ); };