import { useState } from "react"; import type { MessageType } from "@/types/MessageType"; import { postMessage } from "@/api"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { cn } from "@/lib/utils"; interface Props { channelId: string; replyTo: string | null; onClearReply: () => void; onMessageSent: () => void; } const MSG_TYPES: { value: MessageType; label: string }[] = [ { value: "text", label: "T" }, { value: "code", label: "C" }, { value: "result", label: "R" }, { value: "error", label: "E" }, { value: "plan", label: "P" }, ]; export function ComposeBox({ channelId, replyTo, onClearReply, onMessageSent, }: Props) { const [content, setContent] = useState(""); const [msgType, setMsgType] = useState("text"); const [sending, setSending] = useState(false); async function handleSend() { if (!content.trim() || sending) return; setSending(true); try { await postMessage(channelId, { content: content.trim(), type: msgType, reply_to: replyTo ?? undefined, }); setContent(""); setMsgType("text"); onClearReply(); onMessageSent(); } finally { setSending(false); } } return (
{replyTo && (
^ #{replyTo.slice(0, 8)}
)}
{/* Type selector */}
{MSG_TYPES.map((t) => ( ))}
setContent(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); handleSend(); } }} placeholder="message..." disabled={sending} className="flex-1 h-9 md:h-8 text-sm" />
); }