import "./Note.css";
import { useCallback, useMemo } from "react";
import { useNavigate } from "react-router-dom";
import { default as NEvent } from "../nostr/Event";
import ProfileImage from "./ProfileImage";
import Text from "./Text";
import { eventLink, getReactions, hexToBech32 } from "../Util";
import NoteFooter from "./NoteFooter";
import NoteTime from "./NoteTime";
import EventKind from "../nostr/EventKind";
import useProfile from "../feed/ProfileFeed";
import { TaggedRawEvent, u256 } from "../nostr";
import { useInView } from "react-intersection-observer";
export interface NoteProps {
data?: TaggedRawEvent,
isThread?: boolean,
related: TaggedRawEvent[],
highlight?: boolean,
options?: {
showHeader?: boolean,
showTime?: boolean,
showFooter?: boolean
},
["data-ev"]?: NEvent
}
export default function Note(props: NoteProps) {
const navigate = useNavigate();
const { data, isThread, related, highlight, options: opt, ["data-ev"]: parsedEvent } = props
const ev = useMemo(() => parsedEvent ?? new NEvent(data), [data]);
const pubKeys = useMemo(() => ev.Thread?.PubKeys || [], [ev]);
const users = useProfile(pubKeys);
const deletions = useMemo(() => getReactions(related, ev.Id, EventKind.Deletion), [related]);
const { ref, inView } = useInView({ triggerOnce: true });
const options = {
showHeader: true,
showTime: true,
showFooter: true,
...opt
};
const transformBody = useCallback(() => {
let body = ev?.Content ?? "";
if (deletions?.length > 0) {
return (Deleted);
}
return
{JSON.stringify(ev.ToObject(), undefined, ' ')}> ); } function content() { if (!inView) return null; return ( <> {options.showHeader ?