diff --git a/src/components/ChatPanel.tsx b/src/components/ChatPanel.tsx index cef9bdb..7fefde4 100644 --- a/src/components/ChatPanel.tsx +++ b/src/components/ChatPanel.tsx @@ -6,7 +6,6 @@ import { ChatMessage, getProjectChat, getChatMessages, - sendChatMessage, } from "@/lib/api"; import { wsClient } from "@/lib/ws"; @@ -20,7 +19,6 @@ export default function ChatPanel({ projectId }: ChatPanelProps) { const [input, setInput] = useState(""); const [expanded, setExpanded] = useState(false); const [collapsed, setCollapsed] = useState(false); - const [sending, setSending] = useState(false); const messagesEndRef = useRef(null); const inputRef = useRef(null); @@ -72,27 +70,20 @@ export default function ChatPanel({ projectId }: ChatPanelProps) { messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages]); - const handleSend = async () => { - if (!chat || !input.trim() || sending) return; + const handleSend = () => { + if (!chat || !input.trim()) return; const text = input.trim(); setInput(""); - setSending(true); - try { - // Send via REST (gets saved + we get it back via WS broadcast) - const msg = await sendChatMessage(chat.id, text); - // Add immediately (WS might duplicate — deduplicate by id) - setMessages((prev) => { - if (prev.find((m) => m.id === msg.id)) return prev; - return [...prev, msg]; - }); - } catch (e) { - console.error("Failed to send message:", e); - setInput(text); // restore on failure - } finally { - setSending(false); - inputRef.current?.focus(); - } + // Send via WebSocket — message will come back via chat.message event + wsClient.send("chat.send", { + chat_id: chat.id, + content: text, + sender_type: "human", + sender_name: "admin", + }); + + inputRef.current?.focus(); }; const handleKeyDown = (e: React.KeyboardEvent) => { @@ -180,11 +171,11 @@ export default function ChatPanel({ projectId }: ChatPanelProps) { onKeyDown={handleKeyDown} placeholder="Написать сообщение..." className="flex-1 bg-[var(--bg)] border border-[var(--border)] rounded px-3 py-1.5 text-sm outline-none focus:border-[var(--accent)]" - disabled={!chat || sending} + disabled={!chat} />