diff --git a/src/components/feed/InlineReplyBox.tsx b/src/components/feed/InlineReplyBox.tsx new file mode 100644 index 0000000..ace45be --- /dev/null +++ b/src/components/feed/InlineReplyBox.tsx @@ -0,0 +1,96 @@ +import { useState, useRef } from "react"; +import { NDKEvent } from "@nostr-dev-kit/ndk"; +import { publishReply } from "../../lib/nostr"; +import { useReplyCount } from "../../hooks/useReplyCount"; +import { EmojiPicker } from "../shared/EmojiPicker"; + +interface InlineReplyBoxProps { + event: NDKEvent; + name: string; +} + +export function InlineReplyBox({ event, name }: InlineReplyBoxProps) { + const [replyText, setReplyText] = useState(""); + const [replying, setReplying] = useState(false); + const [replyError, setReplyError] = useState(null); + const [replySent, setReplySent] = useState(false); + const [showReplyEmoji, setShowReplyEmoji] = useState(false); + const replyRef = useRef(null); + const [, adjustReplyCount] = useReplyCount(event.id); + + const handleReplySubmit = async () => { + if (!replyText.trim() || replying) return; + setReplying(true); + setReplyError(null); + try { + await publishReply(replyText.trim(), { id: event.id, pubkey: event.pubkey }); + setReplyText(""); + setReplySent(true); + adjustReplyCount(1); + setTimeout(() => { setReplySent(false); }, 1500); + } catch (err) { + setReplyError(`Failed: ${err}`); + } finally { + setReplying(false); + } + }; + + const handleReplyKeyDown = (e: React.KeyboardEvent) => { + if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) handleReplySubmit(); + if (e.key === "Escape") { + // Parent controls visibility — just blur + replyRef.current?.blur(); + } + }; + + return ( +
+