import { useState, useRef } from "react"; import { NDKEvent } from "@nostr-dev-kit/ndk"; import type { ThreadNode as ThreadNodeType } from "../../lib/threadTree"; import { NoteCard } from "../feed/NoteCard"; import { publishReply } from "../../lib/nostr"; import { useProfile } from "../../hooks/useProfile"; import { shortenPubkey } from "../../lib/utils"; import { EmojiPicker } from "../shared/EmojiPicker"; interface ThreadNodeProps { node: ThreadNodeType; rootEvent: NDKEvent; onReplyPublished: (reply: NDKEvent) => void; focusedId?: string; mutedPubkeys: string[]; contentMatchesMutedKeyword: (content: string) => boolean; } const MAX_VISIBLE_CHILDREN = 3; const MAX_INDENT_DEPTH = 4; function InlineThreadReply({ replyTo, rootEvent, onPublished }: { replyTo: NDKEvent; rootEvent: NDKEvent; onPublished: (reply: NDKEvent) => void; }) { const profile = useProfile(replyTo.pubkey); const name = profile?.displayName || profile?.name || shortenPubkey(replyTo.pubkey); const [text, setText] = useState(""); const [replying, setReplying] = useState(false); const [sent, setSent] = useState(false); const [showEmoji, setShowEmoji] = useState(false); const ref = useRef(null); const handleSubmit = async () => { if (!text.trim() || replying) return; setReplying(true); try { const rootArg = replyTo.id !== rootEvent.id ? { id: rootEvent.id, pubkey: rootEvent.pubkey } : undefined; const reply = await publishReply(text.trim(), { id: replyTo.id, pubkey: replyTo.pubkey }, rootArg); setText(""); setSent(true); onPublished(reply); setTimeout(() => setSent(false), 2000); } finally { setReplying(false); } }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) handleSubmit(); if (e.key === "Escape") ref.current?.blur(); }; return (
replying to @{name}