1- import React , { useState } from 'react' ;
1+ import React , { useState , useRef , useEffect } from 'react' ;
22import { uploadEmbeddingText , createAccessToken , searchMemories } from '../services/api' ;
33
44function MessageInput ( { input, setInput, handleSubmit, isLoading, isStreaming, onCancel, onEmbedUpload, chatSessionId, onAuthError } ) {
@@ -16,6 +16,20 @@ function MessageInput({ input, setInput, handleSubmit, isLoading, isStreaming, o
1616 const [ isTokenLoading , setIsTokenLoading ] = useState ( false ) ;
1717 const [ createdToken , setCreatedToken ] = useState ( '' ) ;
1818
19+ // Ref for the message input field
20+ const inputRef = useRef ( null ) ;
21+
22+ // Auto-focus the input when component mounts and when loading completes
23+ useEffect ( ( ) => {
24+ // Focus the input when not loading and not streaming
25+ if ( ! isLoading && ! isStreaming && inputRef . current && chatSessionId ) {
26+ // Small delay to ensure the component is fully rendered
27+ setTimeout ( ( ) => {
28+ inputRef . current . focus ( ) ;
29+ } , 100 ) ;
30+ }
31+ } , [ isLoading , isStreaming , chatSessionId ] ) ;
32+
1933 const handleEmbedSubmit = async ( e ) => {
2034 e . preventDefault ( ) ;
2135 if ( ! embedText . trim ( ) ) return ;
@@ -100,6 +114,7 @@ function MessageInput({ input, setInput, handleSubmit, isLoading, isStreaming, o
100114 < div className = "border-t border-gray-700 p-4" >
101115 < form onSubmit = { handleSubmit } className = "flex gap-2" >
102116 < input
117+ ref = { inputRef }
103118 type = "text"
104119 value = { input }
105120 onChange = { ( e ) => setInput ( e . target . value ) }
0 commit comments