NamH d55a83888b
refactor: replacing mobx with jotai (#160)
* refactor: replacing mobx with jotai

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
Co-authored-by: Louis <louis@jan.ai>
2023-09-13 21:33:53 -07:00

39 lines
1.1 KiB
TypeScript

"use client";
import { currentPromptAtom } from "@/_helpers/JotaiWrapper";
import useSendChatMessage from "@/_hooks/useSendChatMessage";
import { useAtom } from "jotai";
const BasicPromptInput: React.FC = () => {
const [currentPrompt, setCurrentPrompt] = useAtom(currentPromptAtom);
const { sendChatMessage } = useSendChatMessage();
const handleMessageChange = (event: any) => {
setCurrentPrompt(event.target.value);
};
const handleKeyDown = (event: any) => {
if (event.key === "Enter") {
if (!event.shiftKey) {
event.preventDefault();
sendChatMessage();
}
}
};
return (
<textarea
onKeyDown={handleKeyDown}
value={currentPrompt}
onChange={handleMessageChange}
rows={2}
name="comment"
id="comment"
className="overflow-hidden block w-full scroll resize-none border-0 bg-transparent py-1.5 text-gray-900 transition-height duration-200 placeholder:text-gray-400 sm:text-sm sm:leading-6 dark:text-white"
placeholder="Add your comment..."
/>
);
};
export default BasicPromptInput;