"use client"; import { currentPromptAtom } from "@/_helpers/JotaiWrapper"; import { getActiveConvoIdAtom } from "@/_helpers/atoms/Conversation.atom"; import { selectedModelAtom } from "@/_helpers/atoms/Model.atom"; import useCreateConversation from "@/_hooks/useCreateConversation"; import useInitModel from "@/_hooks/useInitModel"; import useSendChatMessage from "@/_hooks/useSendChatMessage"; import { useAtom, useAtomValue } from "jotai"; import { ChangeEvent, useEffect, useRef } from "react"; const BasicPromptInput: React.FC = () => { const activeConversationId = useAtomValue(getActiveConvoIdAtom); const selectedModel = useAtomValue(selectedModelAtom); const [currentPrompt, setCurrentPrompt] = useAtom(currentPromptAtom); const { sendChatMessage } = useSendChatMessage(); const { requestCreateConvo } = useCreateConversation(); const { initModel } = useInitModel(); const textareaRef = useRef(null); const handleKeyDown = async ( event: React.KeyboardEvent ) => { if (event.key === "Enter") { if (!event.shiftKey) { if (activeConversationId) { event.preventDefault(); sendChatMessage(); } else { if (!selectedModel) { console.log("No model selected"); return; } await requestCreateConvo(selectedModel); await initModel(selectedModel); sendChatMessage(); } } } }; useEffect(() => { adjustTextareaHeight(); }, [currentPrompt]); const handleMessageChange = (event: ChangeEvent) => { setCurrentPrompt(event.target.value); }; // Auto adjust textarea height based on content const MAX_ROWS = 10; const adjustTextareaHeight = () => { if (textareaRef.current) { textareaRef.current.style.height = "auto"; // 1 row const scrollHeight = textareaRef.current.scrollHeight; const maxScrollHeight = parseInt(window.getComputedStyle(textareaRef.current).lineHeight, 10) * MAX_ROWS; textareaRef.current.style.height = `${Math.min( scrollHeight, maxScrollHeight )}px`; } }; return (