fix NostrLink element note links

This commit is contained in:
Kieran 2023-03-25 23:13:14 +00:00
parent 9b6e5090dc
commit 8b8d1e6255
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941

View File

@ -1,8 +1,8 @@
import { encodeTLV, NostrPrefix } from "@snort/nostr";
import { NostrPrefix } from "@snort/nostr";
import { Link } from "react-router-dom";
import Mention from "Element/Mention";
import { parseNostrLink } from "Util";
import { eventLink, parseNostrLink } from "Util";
export default function NostrLink({ link }: { link: string }) {
const nav = parseNostrLink(link);
@ -10,11 +10,10 @@ export default function NostrLink({ link }: { link: string }) {
if (nav?.type === NostrPrefix.PublicKey || nav?.type === NostrPrefix.Profile) {
return <Mention pubkey={nav.id} relays={nav.relays} />;
} else if (nav?.type === NostrPrefix.Note || nav?.type === NostrPrefix.Event) {
// translate all "event" links to nevent
const evLink = encodeTLV(nav.id, NostrPrefix.Event, nav.relays);
const evLink = eventLink(nav.id, nav.relays);
return (
<Link to={`/e/${evLink}`} onClick={e => e.stopPropagation()} state={{ from: location.pathname }}>
#{evLink.substring(0, 12)}
<Link to={evLink} onClick={e => e.stopPropagation()} state={{ from: location.pathname }}>
#{evLink.split("/").at(-1)?.substring(0, 12)}
</Link>
);
} else {