"use client"; import { useRef, useState } from "react"; import { ArrowUp } from "lucide-react"; import { Button } from "@/components/ui/button"; import { RichTextEditor, type RichTextEditorRef } from "@/components/common/rich-text-editor"; import { ActorAvatar } from "@/components/common/actor-avatar"; // --------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------- interface ReplyInputProps { placeholder?: string; avatarType: string; avatarId: string; onSubmit: (content: string) => Promise; size?: "sm" | "default"; } // --------------------------------------------------------------------------- // ReplyInput // --------------------------------------------------------------------------- function ReplyInput({ placeholder = "Leave a reply...", avatarType, avatarId, onSubmit, size = "default", }: ReplyInputProps) { const editorRef = useRef(null); const [isEmpty, setIsEmpty] = useState(true); const [submitting, setSubmitting] = useState(false); const handleSubmit = async () => { const content = editorRef.current?.getMarkdown()?.trim(); if (!content || submitting) return; setSubmitting(true); try { await onSubmit(content); editorRef.current?.clearContent(); setIsEmpty(true); } finally { setSubmitting(false); } }; const avatarSize = size === "sm" ? 22 : 28; return (
setIsEmpty(!md.trim())} onSubmit={handleSubmit} debounceMs={100} />
); } export { ReplyInput, type ReplyInputProps };