2023-06-15 12:52:46 +03:00
|
|
|
/* eslint-disable */
|
2023-06-11 00:59:16 +03:00
|
|
|
"use client";
|
2023-06-13 17:33:41 +03:00
|
|
|
import Button from "@/lib/components/ui/Button";
|
|
|
|
import useChatsContext from "@/lib/context/ChatsProvider/hooks/useChatsContext";
|
2023-06-15 12:52:46 +03:00
|
|
|
|
2023-06-11 00:59:16 +03:00
|
|
|
import { ConfigButton } from "./ConfigButton";
|
|
|
|
import { MicButton } from "./MicButton";
|
|
|
|
|
2023-06-15 12:52:46 +03:00
|
|
|
export const ChatInput = (): JSX.Element => {
|
2023-06-11 15:34:36 +03:00
|
|
|
const { isSendingMessage, sendMessage, setMessage, message, chat } =
|
|
|
|
useChatsContext();
|
2023-06-15 12:52:46 +03:00
|
|
|
|
2023-06-11 00:59:16 +03:00
|
|
|
return (
|
|
|
|
<form
|
|
|
|
onSubmit={(e) => {
|
|
|
|
e.preventDefault();
|
2023-06-15 12:52:46 +03:00
|
|
|
if (!isSendingMessage) {
|
|
|
|
sendMessage(chat?.chatId);
|
|
|
|
}
|
2023-06-11 00:59:16 +03:00
|
|
|
}}
|
2023-06-11 11:44:23 +03:00
|
|
|
className="sticky bottom-0 p-5 bg-white dark:bg-black rounded-t-md border border-black/10 dark:border-white/25 border-b-0 w-full max-w-3xl flex items-center justify-center gap-2 z-20"
|
2023-06-11 00:59:16 +03:00
|
|
|
>
|
|
|
|
<textarea
|
|
|
|
autoFocus
|
|
|
|
value={message[1]}
|
|
|
|
onChange={(e) => setMessage((msg) => [msg[0], e.target.value])}
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
|
|
e.preventDefault(); // Prevents the newline from being entered in the textarea
|
2023-06-15 12:52:46 +03:00
|
|
|
if (!isSendingMessage) {
|
|
|
|
sendMessage(chat?.chatId);
|
|
|
|
} // Call the submit function here
|
2023-06-11 00:59:16 +03:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
className="w-full p-2 border border-gray-300 dark:border-gray-500 outline-none rounded dark:bg-gray-800"
|
|
|
|
placeholder="Begin conversation here..."
|
|
|
|
/>
|
2023-06-14 23:58:37 +03:00
|
|
|
<Button
|
|
|
|
className="px-3 py-2 sm:px-4 sm:py-2"
|
|
|
|
type="submit"
|
|
|
|
isLoading={isSendingMessage}
|
|
|
|
>
|
2023-06-11 00:59:16 +03:00
|
|
|
{isSendingMessage ? "Thinking..." : "Chat"}
|
|
|
|
</Button>
|
2023-06-14 23:58:37 +03:00
|
|
|
<div className="flex items-center">
|
|
|
|
<MicButton />
|
|
|
|
<ConfigButton />
|
|
|
|
</div>
|
2023-06-11 00:59:16 +03:00
|
|
|
</form>
|
|
|
|
);
|
2023-06-15 12:52:46 +03:00
|
|
|
};
|