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

26 lines
917 B
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";
2023-10-17 22:01:53 +00:00
import { useHover } from "@uidotdev/usehooks";
2023-03-25 22:55:34 +00:00
2023-11-17 11:52:10 +00:00
import DisplayName from "@/Element/User/DisplayName";
import { ProfileCard } from "@/Element/User/ProfileCard";
import { ProfileLink } from "@/Element/User/ProfileLink";
export default function Mention({ link }: { link: NostrLink }) {
2023-10-17 22:01:53 +00:00
const [ref, hovering] = useHover<HTMLAnchorElement>();
const profile = useUserProfile(link.id);
if (link.type !== NostrPrefix.Profile && link.type !== NostrPrefix.PublicKey) return;
2023-01-16 22:22:21 +00:00
return (
2023-10-17 22:01:53 +00:00
<>
2023-11-17 21:50:12 +00:00
<ProfileLink pubkey={link.id} link={link} user={profile} onClick={e => e.stopPropagation()}>
2023-10-17 22:01:53 +00:00
<span ref={ref}>
@<DisplayName user={profile} pubkey={link.id} />
</span>
</ProfileLink>
<ProfileCard pubkey={link.id} user={profile} show={hovering} ref={ref} />
</>
);
}