flockstr/components/TextRendering/ProfileMention.tsx
2023-10-20 18:26:53 -04:00

36 lines
878 B
TypeScript

"use client";
import Link from "next/link";
import { nip19 } from "nostr-tools";
import { NOSTR_BECH32_REGEXP } from "@/lib/nostr/utils";
import { useNDK } from "@/app/_providers/ndk";
type ProfileMentionProps = {
mention: string;
};
function getPubkey(mention: string) {
try {
return NOSTR_BECH32_REGEXP.test(mention)
? nip19.decode(mention).data.toString()
: mention;
} catch (err) {
console.log("Error getting pubkey", err);
return "";
}
}
export default function ProfileMention({ mention }: ProfileMentionProps) {
const pubkey = getPubkey(mention);
// const { user } = useProfile(pubkey);
const { getProfile } = useNDK();
const profile = getProfile(mention);
return (
<Link href={`/${mention}`}>
<span className="text-primary hover:underline">{`@${
profile?.name ?? mention
}`}</span>
</Link>
);
}