Add AI chat feature
This commit is contained in:
parent
80056b3728
commit
6a5041be43
15 changed files with 1259 additions and 2 deletions
34
components/chat/chat-form.tsx
Normal file
34
components/chat/chat-form.tsx
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { useState, type SubmitEvent } from "react";
|
||||
import { Button } from "../ui/button";
|
||||
import { Textarea } from "../ui/textarea";
|
||||
import { ArrowUpIcon, SendIcon } from "lucide-react";
|
||||
|
||||
interface ChatFormProps {
|
||||
onMessage: (message: { text: string }) => void;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export function ChatForm({ onMessage, disabled }: ChatFormProps) {
|
||||
const [text, setText] = useState("");
|
||||
|
||||
function handleSubmit(e: SubmitEvent<HTMLFormElement>) {
|
||||
e.preventDefault();
|
||||
if (!text.trim()) return;
|
||||
setText("");
|
||||
onMessage({ text });
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="flex gap-2">
|
||||
<Textarea
|
||||
name="text"
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
className="min-h-18"
|
||||
/>
|
||||
<Button type="submit" disabled={disabled} size="icon-lg">
|
||||
<ArrowUpIcon />
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue