Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Jul 19, 2024
1 parent ef93458 commit 12f5bc9
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions app/src/client/components/ChatForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,32 @@ 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) {
setDisableFormSubmit(currentChatDetails.team_status === 'inprogress');
} else {
setDisableFormSubmit(false);
}
setFocusOnTextArea();
}, [currentChatDetails]);

const submitForm = async (inputValue: string) => {
const submitForm = async () => {
if (isSubmitting || disableFormSubmit || isProcessing.current || isEmptyMessage) return;

const msgToSubmit = formInputValue.trim();
Expand Down Expand Up @@ -85,18 +89,18 @@ export default function ChatForm({ handleFormSubmit, currentChatDetails, trigger

const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
await submitForm(formInputValue);
await submitForm();
};

const handleButtonClick = async (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
await submitForm(formInputValue);
await submitForm();
};

const handleKeyDown = async (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
await submitForm(formInputValue);
await submitForm();
}
};

Expand Down

0 comments on commit 12f5bc9

Please sign in to comment.