feat: refactor chat input handling and add BoardChatComposer component for improved chat functionality

This commit is contained in:
Abhimanyu Saharan
2026-02-06 20:28:48 +05:30
parent e786763250
commit e7dc2d0f8b
2 changed files with 114 additions and 52 deletions

View File

@@ -0,0 +1,57 @@
"use client";
import { memo, useCallback, useState } from "react";
import { Button } from "@/components/ui/button";
import { Textarea } from "@/components/ui/textarea";
type BoardChatComposerProps = {
placeholder?: string;
isSending?: boolean;
onSend: (content: string) => Promise<boolean>;
};
function BoardChatComposerImpl({
placeholder = "Message the board lead. Tag agents with @name.",
isSending = false,
onSend,
}: BoardChatComposerProps) {
const [value, setValue] = useState("");
const send = useCallback(async () => {
if (isSending) return;
const trimmed = value.trim();
if (!trimmed) return;
const ok = await onSend(trimmed);
if (ok) {
setValue("");
}
}, [isSending, onSend, value]);
return (
<div className="mt-4 space-y-2">
<Textarea
value={value}
onChange={(event) => setValue(event.target.value)}
onKeyDown={(event) => {
if (event.key !== "Enter") return;
if (event.nativeEvent.isComposing) return;
if (event.shiftKey) return;
event.preventDefault();
void send();
}}
placeholder={placeholder}
className="min-h-[120px]"
disabled={isSending}
/>
<div className="flex justify-end">
<Button onClick={() => void send()} disabled={isSending || !value.trim()}>
{isSending ? "Sending…" : "Send"}
</Button>
</div>
</div>
);
}
export const BoardChatComposer = memo(BoardChatComposerImpl);
BoardChatComposer.displayName = "BoardChatComposer";