Fix broken note links (#380)

* fix broken note links

* remove unused prop

* make comment easier to understand

* handle case where root event ID is missing

* add missing return

* fix root finding logic

* update comment
This commit is contained in:
Sam Samskies
2023-03-04 11:41:29 -10:00
committed by GitHub
parent 7928670153
commit 0a5491eede
3 changed files with 36 additions and 7 deletions

View File

@ -1,6 +1,6 @@
import "./Text.css";
import { useMemo, useCallback } from "react";
import { Link } from "react-router-dom";
import { Link, useLocation } from "react-router-dom";
import ReactMarkdown from "react-markdown";
import { visit, SKIP } from "unist-util-visit";
import * as unist from "unist";
@ -28,6 +28,8 @@ export interface TextProps {
}
export default function Text({ content, tags, creator }: TextProps) {
const location = useLocation();
function extractLinks(fragments: Fragment[]) {
return fragments
.map(f => {
@ -80,7 +82,10 @@ export default function Text({ content, tags, creator }: TextProps) {
case "e": {
const eText = hexToBech32("note", ref.Event).substring(0, 12);
return (
<Link to={eventLink(ref.Event ?? "")} onClick={e => e.stopPropagation()}>
<Link
to={eventLink(ref.Event ?? "")}
onClick={e => e.stopPropagation()}
state={{ from: location.pathname }}>
#{eText}
</Link>
);