fix usernames on notes showing @

This commit is contained in:
hzrd149
2023-02-07 17:04:19 -06:00
parent 33d57ddc71
commit fe0fd2197c
2 changed files with 6 additions and 4 deletions

View File

@ -199,7 +199,7 @@ const embeds: EmbedType[] = [
switch (match[2]) { switch (match[2]) {
case "npub1": case "npub1":
const id = normalizeToHex(match[1]); const id = normalizeToHex(match[1]);
return id ? <UserLink color="blue.500" pubkey={id} /> : match[0]; return id ? <UserLink color="blue.500" pubkey={id} showAt /> : match[0];
default: default:
return match[0]; return match[0];
} }
@ -215,7 +215,7 @@ const embeds: EmbedType[] = [
if (tag) { if (tag) {
if (tag[0] === "p" && tag[1]) { if (tag[0] === "p" && tag[1]) {
return <UserLink color="blue.500" pubkey={tag[1]} />; return <UserLink color="blue.500" pubkey={tag[1]} showAt />;
} }
if (tag[0] === "e" && tag[1]) { if (tag[0] === "e" && tag[1]) {
return <NoteLink color="blue.500" noteId={tag[1]} />; return <NoteLink color="blue.500" noteId={tag[1]} />;

View File

@ -6,15 +6,17 @@ import { useUserMetadata } from "../hooks/use-user-metadata";
export type UserLinkProps = LinkProps & { export type UserLinkProps = LinkProps & {
pubkey: string; pubkey: string;
showAt?: boolean;
}; };
export const UserLink = ({ pubkey, ...props }: UserLinkProps) => { export const UserLink = ({ pubkey, showAt, ...props }: UserLinkProps) => {
const metadata = useUserMetadata(pubkey); const metadata = useUserMetadata(pubkey);
const npub = normalizeToBech32(pubkey, Bech32Prefix.Pubkey); const npub = normalizeToBech32(pubkey, Bech32Prefix.Pubkey);
return ( return (
<Link as={RouterLink} to={`/u/${npub}`} whiteSpace="nowrap" {...props}> <Link as={RouterLink} to={`/u/${npub}`} whiteSpace="nowrap" {...props}>
@{getUserDisplayName(metadata, pubkey)} {showAt && "@"}
{getUserDisplayName(metadata, pubkey)}
</Link> </Link>
); );
}; };