snort/packages/app/src/Components/Embed/Mention.tsx

36 lines
1.5 KiB
TypeScript
Raw Normal View History

import { NostrLink, NostrPrefix } from "@snort/system";
2023-06-16 19:31:33 +00:00
import { useUserProfile } from "@snort/system-react";
2024-01-04 17:01:18 +00:00
import { useCallback, useRef, useState } from "react";
2023-03-25 22:55:34 +00:00
import DisplayName from "@/Components/User/DisplayName";
import { ProfileCard } from "@/Components/User/ProfileCard";
import { ProfileLink } from "@/Components/User/ProfileLink";
export default function Mention({ link }: { link: NostrLink }) {
const profile = useUserProfile(link.id);
2023-11-25 20:53:50 +00:00
const [isHovering, setIsHovering] = useState(false);
const hoverTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const handleMouseEnter = useCallback(() => {
hoverTimeoutRef.current && clearTimeout(hoverTimeoutRef.current);
hoverTimeoutRef.current = setTimeout(() => setIsHovering(true), 100); // Adjust timeout as needed
}, []);
const handleMouseLeave = useCallback(() => {
hoverTimeoutRef.current && clearTimeout(hoverTimeoutRef.current);
hoverTimeoutRef.current = setTimeout(() => setIsHovering(false), 300); // Adjust timeout as needed
}, []);
if (link.type !== NostrPrefix.Profile && link.type !== NostrPrefix.PublicKey) return;
2023-01-16 22:22:21 +00:00
return (
2023-11-25 20:53:50 +00:00
<span className="highlight" onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}>
2023-11-17 21:50:12 +00:00
<ProfileLink pubkey={link.id} link={link} user={profile} onClick={e => e.stopPropagation()}>
2023-11-25 20:53:50 +00:00
@<DisplayName user={profile} pubkey={link.id} />
2023-10-17 22:01:53 +00:00
</ProfileLink>
2023-11-25 20:53:50 +00:00
{isHovering && <ProfileCard pubkey={link.id} user={profile} show={true} />}
</span>
);
}