mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-25 12:22:58 +03:00
b0514d6149
* add libraries for traslation purposes * Add button and service for language selection * add spanish translation on login page * add spanish translation on upload page * Add spanish translations for explore page * Add translations on user page * Add translations for config page * Add spanish translations on chat page * add translations for brain page * fix GUI and save on local storage * fix (i18n) init and types * fix (i18n): typos * add translation on new brain modal * add translations on metadata * Add translations on home page * fixes types * fix(frontend-tests): use get by id instead of text --------- Co-authored-by: Gustavo Maciel <gustavo_m13@outlook.com>
62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
/* eslint-disable */
|
|
"use client";
|
|
import Button from "@/lib/components/ui/Button";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { useChat } from "@/app/chat/[chatId]/hooks/useChat";
|
|
import { useState } from "react";
|
|
import { ConfigModal } from "./components/ConfigModal";
|
|
import { MicButton } from "./components/MicButton/MicButton";
|
|
|
|
export const ChatInput = (): JSX.Element => {
|
|
const [message, setMessage] = useState<string>("");
|
|
const { addQuestion, generatingAnswer, chatId } = useChat();
|
|
const { t } = useTranslation(['chat']);
|
|
|
|
const submitQuestion = () => {
|
|
if (message.length === 0) return;
|
|
if (!generatingAnswer) {
|
|
addQuestion(message, () => setMessage(""));
|
|
}
|
|
};
|
|
|
|
return (
|
|
<form
|
|
data-testid="chat-input-form"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
submitQuestion();
|
|
}}
|
|
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"
|
|
>
|
|
<textarea
|
|
autoFocus
|
|
value={message}
|
|
required
|
|
onChange={(e) => setMessage(e.target.value)}
|
|
onKeyDown={(e) => {
|
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
e.preventDefault(); // Prevents the newline from being entered in the textarea
|
|
submitQuestion();
|
|
}
|
|
}}
|
|
className="w-full p-2 border border-gray-300 dark:border-gray-500 outline-none rounded dark:bg-gray-800"
|
|
placeholder= {t('begin_conversation_placeholder')}
|
|
data-testid="chat-input"
|
|
/>
|
|
<Button
|
|
className="px-3 py-2 sm:px-4 sm:py-2"
|
|
type="submit"
|
|
isLoading={generatingAnswer}
|
|
data-testid="submit-button"
|
|
>
|
|
{generatingAnswer ? t('thinking',{ns:'chat'}) : t('chat',{ns:'chat'})}
|
|
</Button>
|
|
<div className="flex items-center">
|
|
<MicButton setMessage={setMessage} />
|
|
<ConfigModal chatId={chatId} />
|
|
</div>
|
|
</form>
|
|
);
|
|
};
|