diff --git a/frontend/src/components/Conversation/Conversation.tsx b/frontend/src/components/Conversation/Conversation.tsx index f565c6b9..03fc7655 100644 --- a/frontend/src/components/Conversation/Conversation.tsx +++ b/frontend/src/components/Conversation/Conversation.tsx @@ -65,6 +65,8 @@ export const Conversation = () => { ); const messageListRef = useRef(null); + const expandingInputRef = useRef(null); + const currConversation = conversationsData?.find( (conv) => conv.id === params.conversationId ); @@ -175,32 +177,35 @@ export const Conversation = () => {
- {messages.length === 0 && ( + {messages.length === 0 && !currentConversationIsQuerying && (
{templateMessages.map((template) => ( + onClick={() => { sendMessageMutation({ message: template.message, conversationId: params.conversationId ?? "", - }) - } + }); + expandingInputRef.current?.focus(); + }} /> ))}
)}
+ onSubmit={(message: string) => { sendMessageMutation({ message, conversationId: params.conversationId ?? "", - }) - } + }); + expandingInputRef.current?.focus(); + }} disabled={currentConversationIsQuerying} + ref={expandingInputRef} />

Current Connection: {currConnection?.name} diff --git a/frontend/src/components/Conversation/ExpandingInput.tsx b/frontend/src/components/Conversation/ExpandingInput.tsx index b949ff30..0ad712bb 100644 --- a/frontend/src/components/Conversation/ExpandingInput.tsx +++ b/frontend/src/components/Conversation/ExpandingInput.tsx @@ -4,7 +4,7 @@ import { ShieldExclamationIcon, ShieldCheckIcon, } from "@heroicons/react/24/outline"; -import { SetStateAction, useRef, useState } from "react"; +import { SetStateAction, forwardRef, useRef, useState } from "react"; import { Switch, SwitchField, SwitchGroup } from "../Catalyst/switch"; import { Description, Fieldset, Label } from "../Catalyst/fieldset"; @@ -19,7 +19,6 @@ import { import { useClickOutside } from "../Library/utils"; import { useQuery } from "@tanstack/react-query"; - type ExpandingInputProps = { onSubmit: (value: string) => void; disabled: boolean; @@ -71,9 +70,7 @@ const MessageSettingsPopup: React.FC = ({

- + Hide your data from the AI model = ({ ); }; -const ExpandingInput: React.FC = ({ - onSubmit, - disabled, -}) => { - const [inputValue, setInputValue] = useState(""); - const [messageSettingsShown, setMessageSettingsShown] = useState(false); - const currConnection = useGetRelatedConnection(); - const { data: messageOptions } = useQuery( - getMessageOptions(currConnection?.id) - ); - const settingsCogRef = useRef(null); - const handleChange = (e: { - target: { - value: SetStateAction; - style: { height: string }; - scrollHeight: any; +const ExpandingInput = forwardRef( + ({ onSubmit, disabled }, ref) => { + const [inputValue, setInputValue] = useState(""); + const [messageSettingsShown, setMessageSettingsShown] = useState(false); + const currConnection = useGetRelatedConnection(); + const { data: messageOptions } = useQuery( + getMessageOptions(currConnection?.id) + ); + const settingsCogRef = useRef(null); + + const handleChange = (e: { + target: { + value: SetStateAction; + style: { height: string }; + scrollHeight: any; + }; + }) => { + setInputValue(e.target.value); + e.target.style.height = "auto"; // Reset textarea height + e.target.style.height = `${e.target.scrollHeight}px`; // Set textarea height based on content }; - }) => { - setInputValue(e.target.value); - e.target.style.height = "auto"; // Reset textarea height - e.target.style.height = `${e.target.scrollHeight}px`; // Set textarea height based on content - }; - const handleSubmit = () => { - if (disabled) return; - if (inputValue.length === 0) return; - onSubmit(inputValue); - setInputValue(""); - }; + const handleSubmit = () => { + if (disabled) return; + if (inputValue.length === 0) return; + onSubmit(inputValue); + setInputValue(""); + }; - const handleKeyPress = (e: React.KeyboardEvent) => { - if (e.key === "Enter" && !e.shiftKey) { - e.preventDefault(); - handleSubmit(); + const handleKeyPress = (e: React.KeyboardEvent) => { + if (e.key === "Enter" && !e.shiftKey) { + e.preventDefault(); + handleSubmit(); - // Reset textarea height - e.currentTarget.style.height = "auto"; - } - }; + // Reset textarea height + e.currentTarget.style.height = "auto"; + } + }; - return ( -
-