forked from Kieran/snort
Show disconnected chains
This commit is contained in:
parent
96146ea7d8
commit
a55fed14dd
@ -8,7 +8,7 @@ export default function NoteGhost(props) {
|
|||||||
<ProfileImage pubkey="" />
|
<ProfileImage pubkey="" />
|
||||||
</div>
|
</div>
|
||||||
<div className="body">
|
<div className="body">
|
||||||
{props.text ?? "Loading..."}
|
{props.children}
|
||||||
</div>
|
</div>
|
||||||
<div className="footer">
|
<div className="footer">
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
import Event from "../nostr/Event";
|
import Event from "../nostr/Event";
|
||||||
import EventKind from "../nostr/EventKind";
|
import EventKind from "../nostr/EventKind";
|
||||||
import Note from "./Note";
|
import Note from "./Note";
|
||||||
@ -24,7 +25,7 @@ export default function Thread(props) {
|
|||||||
} else {
|
} else {
|
||||||
chains.get(replyTo).push(v);
|
chains.get(replyTo).push(v);
|
||||||
}
|
}
|
||||||
} else if(v.Tags.length > 0) {
|
} else if (v.Tags.length > 0) {
|
||||||
console.log("Not replying to anything: ", v);
|
console.log("Not replying to anything: ", v);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -32,6 +33,10 @@ export default function Thread(props) {
|
|||||||
return chains;
|
return chains;
|
||||||
}, [notes]);
|
}, [notes]);
|
||||||
|
|
||||||
|
const brokenChains = useMemo(() => {
|
||||||
|
return Array.from(chains?.keys()).filter(a => !notes.some(b => b.Id === a));
|
||||||
|
}, [chains]);
|
||||||
|
|
||||||
function reactions(id, kind = EventKind.Reaction) {
|
function reactions(id, kind = EventKind.Reaction) {
|
||||||
return notes?.filter(a => a.Kind === kind && a.Tags.find(a => a.Key === "e" && a.Event === id));
|
return notes?.filter(a => a.Kind === kind && a.Tags.find(a => a.Key === "e" && a.Event === id));
|
||||||
}
|
}
|
||||||
@ -40,11 +45,13 @@ export default function Thread(props) {
|
|||||||
if (root) {
|
if (root) {
|
||||||
return <Note data-ev={root} reactions={reactions(root.Id)} deletion={reactions(root.Id, EventKind.Deletion)} />
|
return <Note data-ev={root} reactions={reactions(root.Id)} deletion={reactions(root.Id, EventKind.Deletion)} />
|
||||||
} else {
|
} else {
|
||||||
return <NoteGhost text={`Loading thread.. ${notes.length} loaded`} />
|
return <NoteGhost>
|
||||||
|
Loading thread root.. ({notes.length} notes loaded)
|
||||||
|
</NoteGhost>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderChain(from, acc) {
|
function renderChain(from) {
|
||||||
if (from && chains) {
|
if (from && chains) {
|
||||||
let replies = chains.get(from);
|
let replies = chains.get(from);
|
||||||
if (replies) {
|
if (replies) {
|
||||||
@ -68,6 +75,19 @@ export default function Thread(props) {
|
|||||||
<>
|
<>
|
||||||
{renderRoot()}
|
{renderRoot()}
|
||||||
{root ? renderChain(root.Id) : null}
|
{root ? renderChain(root.Id) : null}
|
||||||
|
{root ? null : <>
|
||||||
|
<h3>Other Replies</h3>
|
||||||
|
{brokenChains.map(a => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<NoteGhost>
|
||||||
|
Missing event <Link to={`/e/${a}`}>{a.substring(0, 8)}</Link>
|
||||||
|
</NoteGhost>
|
||||||
|
{renderChain(a)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</>}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
import Nostrich from "../nostrich.jpg";
|
|
||||||
import { useEffect, useMemo } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import EventKind from "../nostr/EventKind";
|
import EventKind from "../nostr/EventKind";
|
||||||
|
@ -42,11 +42,15 @@ export default function useUsersCache() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function mapEventToProfile(ev) {
|
export function mapEventToProfile(ev) {
|
||||||
let data = JSON.parse(ev.content);
|
try {
|
||||||
return {
|
let data = JSON.parse(ev.content);
|
||||||
pubkey: ev.pubkey,
|
return {
|
||||||
fromEvent: ev,
|
pubkey: ev.pubkey,
|
||||||
loaded: new Date().getTime(),
|
fromEvent: ev,
|
||||||
...data
|
loaded: new Date().getTime(),
|
||||||
};
|
...data
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to parse JSON", ev, e);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user