From 06c29500f2bd6ae542c517fde41379832f9d3295 Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Wed, 14 May 2025 04:13:53 +0530 Subject: [PATCH] (fix:input-lag) localised the input state to messageInput --- frontend/src/components/MessageInput.tsx | 19 ++++++++++++------- frontend/src/conversation/Conversation.tsx | 18 ++++++++---------- .../src/conversation/SharedConversation.tsx | 16 +++++++--------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/frontend/src/components/MessageInput.tsx b/frontend/src/components/MessageInput.tsx index 532cc599..79487188 100644 --- a/frontend/src/components/MessageInput.tsx +++ b/frontend/src/components/MessageInput.tsx @@ -30,9 +30,7 @@ import SourcesPopup from './SourcesPopup'; import ToolsPopup from './ToolsPopup'; type MessageInputProps = { - value: string; - onChange: (e: React.ChangeEvent) => void; - onSubmit: () => void; + onSubmit: (text: string) => void; loading: boolean; showSourceButton?: boolean; showToolButton?: boolean; @@ -40,8 +38,6 @@ type MessageInputProps = { }; export default function MessageInput({ - value, - onChange, onSubmit, loading, showSourceButton = true, @@ -50,6 +46,7 @@ export default function MessageInput({ }: MessageInputProps) { const { t } = useTranslation(); const [isDarkTheme] = useDarkTheme(); + const [value, setValue] = useState(''); const inputRef = useRef(null); const sourceButtonRef = useRef(null); const toolButtonRef = useRef(null); @@ -232,6 +229,11 @@ export default function MessageInput({ handleInput(); }, []); + const handleChange = (e: React.ChangeEvent) => { + setValue(e.target.value); + handleInput(); + }; + const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); @@ -248,7 +250,10 @@ export default function MessageInput({ }; const handleSubmit = () => { - onSubmit(); + if (value.trim() && !loading) { + onSubmit(value); + setValue(''); + } }; return (
@@ -334,7 +339,7 @@ export default function MessageInput({ id="message-input" ref={inputRef} value={value} - onChange={onChange} + onChange={handleChange} tabIndex={1} placeholder={t('inputPlaceholder')} className="inputbox-style no-scrollbar w-full overflow-y-auto overflow-x-hidden whitespace-pre-wrap rounded-t-[23px] bg-lotion px-4 py-3 text-base leading-tight opacity-100 focus:outline-none dark:bg-transparent dark:text-bright-gray dark:placeholder-bright-gray dark:placeholder-opacity-50 sm:px-6 sm:py-5" diff --git a/frontend/src/conversation/Conversation.tsx b/frontend/src/conversation/Conversation.tsx index bbe96d9c..753a3725 100644 --- a/frontend/src/conversation/Conversation.tsx +++ b/frontend/src/conversation/Conversation.tsx @@ -39,7 +39,6 @@ export default function Conversation() { const conversationId = useSelector(selectConversationId); const selectedAgent = useSelector(selectSelectedAgent); - const [input, setInput] = useState(''); const [uploadModalState, setUploadModalState] = useState('INACTIVE'); const [files, setFiles] = useState([]); @@ -143,19 +142,19 @@ export default function Conversation() { }; const handleQuestionSubmission = ( - updatedQuestion?: string, + question?: string, updated?: boolean, indx?: number, ) => { if (updated === true) { - handleQuestion({ question: updatedQuestion as string, index: indx }); - } else if (input && status !== 'loading') { + handleQuestion({ question: question as string, index: indx }); + } else if (question && status !== 'loading') { if (lastQueryReturnedErr) { dispatch( updateQuery({ index: queries.length - 1, query: { - prompt: input, + prompt: question, }, }), ); @@ -165,10 +164,9 @@ export default function Conversation() { }); } else { handleQuestion({ - question: input, + question, }); } - setInput(''); } }; @@ -207,9 +205,9 @@ export default function Conversation() { setInput(e.target.value)} - onSubmit={handleQuestionSubmission} + onSubmit={(text) => { + handleQuestionSubmission(text); + }} loading={status === 'loading'} showSourceButton={selectedAgent ? false : true} showToolButton={selectedAgent ? false : true} diff --git a/frontend/src/conversation/SharedConversation.tsx b/frontend/src/conversation/SharedConversation.tsx index e7612ab7..3627c048 100644 --- a/frontend/src/conversation/SharedConversation.tsx +++ b/frontend/src/conversation/SharedConversation.tsx @@ -35,7 +35,6 @@ export const SharedConversation = () => { const apiKey = useSelector(selectClientAPIKey); const status = useSelector(selectStatus); - const [input, setInput] = useState(''); const { t } = useTranslation(); const dispatch = useDispatch(); @@ -76,15 +75,15 @@ export const SharedConversation = () => { }); }; - const handleQuestionSubmission = () => { - if (input && status !== 'loading') { + const handleQuestionSubmission = (question?: string) => { + if (question && status !== 'loading') { if (lastQueryReturnedErr) { // update last failed query with new prompt dispatch( updateQuery({ index: queries.length - 1, query: { - prompt: input, + prompt: question, }, }), ); @@ -93,9 +92,8 @@ export const SharedConversation = () => { isRetry: true, }); } else { - handleQuestion({ question: input }); + handleQuestion({ question }); } - setInput(''); } }; @@ -156,9 +154,9 @@ export const SharedConversation = () => {
{apiKey ? ( setInput(e.target.value)} - onSubmit={() => handleQuestionSubmission()} + onSubmit={(text) => { + handleQuestionSubmission(text); + }} loading={status === 'loading'} showSourceButton={false} showToolButton={false}