diff --git a/app/src/client/components/ChatForm.tsx b/app/src/client/components/ChatForm.tsx index 7f53eec..1fc25eb 100644 --- a/app/src/client/components/ChatForm.tsx +++ b/app/src/client/components/ChatForm.tsx @@ -31,18 +31,21 @@ export default function ChatForm({ handleFormSubmit, currentChatDetails, trigger [triggerChatFormSubmitMsg] ); + const setFocusOnTextArea = () => { + if (textAreaRef.current) { + textAreaRef.current.focus(); + } + }; useEffect(() => { - if (toggleTextAreaFocus && (!disableFormSubmit || !isSubmitting || !isProcessing.current)) { - if (textAreaRef.current) { - textAreaRef.current.focus(); - } + const responseCompleted = !disableFormSubmit || !isSubmitting || !isProcessing.current; + if (toggleTextAreaFocus && responseCompleted) { + setFocusOnTextArea(); } }, [disableFormSubmit, isSubmitting, isProcessing.current, toggleTextAreaFocus]); - const setFocusOnTextArea = () => { + useSocketListener('streamFromTeamFinished', () => { setToggleTextAreaFocus(true); - }; - useSocketListener('streamFromTeamFinished', setFocusOnTextArea); + }); useEffect(() => { if (currentChatDetails) { @@ -50,9 +53,10 @@ export default function ChatForm({ handleFormSubmit, currentChatDetails, trigger } else { setDisableFormSubmit(false); } + setFocusOnTextArea(); }, [currentChatDetails]); - const submitForm = async (inputValue: string) => { + const submitForm = async () => { if (isSubmitting || disableFormSubmit || isProcessing.current || isEmptyMessage) return; const msgToSubmit = formInputValue.trim(); @@ -85,18 +89,18 @@ export default function ChatForm({ handleFormSubmit, currentChatDetails, trigger const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); - await submitForm(formInputValue); + await submitForm(); }; const handleButtonClick = async (event: React.MouseEvent) => { event.preventDefault(); - await submitForm(formInputValue); + await submitForm(); }; const handleKeyDown = async (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); - await submitForm(formInputValue); + await submitForm(); } };