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:
@ -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>
|
||||
);
|
||||
|
Reference in New Issue
Block a user