import "./NoteReaction.css"; import EventKind from "../nostr/EventKind"; import Note from "./Note"; import ProfileImage from "./ProfileImage"; import Event from "../nostr/Event"; import { eventLink, hexToBech32 } from "../Util"; import { Link } from "react-router-dom"; import { useMemo } from "react"; import NoteTime from "./NoteTime"; export default function NoteReaction(props) { const ev = props["data-ev"] || Event.FromObject(props.data); const refEvent = useMemo(() => { if (ev) { let eTags = ev.Tags.filter(a => a.Key === "e"); if (eTags.length > 0) { return eTags[0].Event; } } return null; }, [ev]); if (ev.Kind !== EventKind.Reaction && ev.Kind !== EventKind.Repost) { return null; } function mapReaction(c) { switch (c) { case "+": return "❤️"; case "-": return "👎"; default: { if (c.length === 0) { return "❤️"; } return c; } } } function tagLine() { switch (ev.Kind) { case EventKind.Reaction: return reacted with {mapReaction(ev.Content)}; case EventKind.Repost: return reposted } } /** * Some clients embed the reposted note in the content */ function extractRoot() { if (ev?.Kind === EventKind.Repost && ev.Content.length > 0) { try { let r = JSON.parse(ev.Content); return r; } catch (e) { console.error("Could not load reposted content", e); } } return props.root; } const root = extractRoot(); const opt = { showHeader: ev?.Kind === EventKind.Repost, showFooter: ev?.Kind === EventKind.Repost, }; return (
#{hexToBech32("note", refEvent).substring(0, 12)}
: null}