@@ -17,7 +17,7 @@ interface CommandResult {
1717
1818function REPL ( ) {
1919 const [ client , setClient ] = useState < HttpClient | null > ( null ) ;
20- const [ isConnected , setIsConnected ] = useState ( false ) ;
20+ const [ connectionStatus , setConnectionStatus ] = useState < "disconnected" | "connecting" | "connected" > ( "disconnected" ) ;
2121 const [ sessionId , setSessionId ] = useState < string | null > ( null ) ;
2222 const [ commandInput , setCommandInput ] = useState ( "" ) ;
2323 const [ results , setResults ] = useState < CommandResult [ ] > ( [ ] ) ;
@@ -109,18 +109,20 @@ function REPL() {
109109 // Initialize connection by creating a session
110110 const initializeConnection = async ( ) => {
111111 try {
112+ setConnectionStatus ( "connecting" ) ;
113+
112114 // Test connection with ping
113115 await httpClient . ping ( ) ;
114116 console . log ( "Server is reachable" ) ;
115117
116118 // Create a session
117119 const session = await httpClient . createSession ( ) ;
118120 setSessionId ( session ) ;
119- setIsConnected ( true ) ;
121+ setConnectionStatus ( "connected" ) ;
120122 console . log ( "Connected with session:" , session ) ;
121123 } catch ( error : any ) {
122124 console . error ( "Failed to connect:" , error ) ;
123- setIsConnected ( false ) ;
125+ setConnectionStatus ( "disconnected" ) ;
124126 }
125127 } ;
126128
@@ -135,7 +137,7 @@ function REPL() {
135137 } , [ ] ) ;
136138
137139 const executeCommand = async ( ) => {
138- if ( ! client || ! isConnected || ! commandInput . trim ( ) || isExecuting ) {
140+ if ( ! client || connectionStatus !== "connected" || ! commandInput . trim ( ) || isExecuting ) {
139141 return ;
140142 }
141143
@@ -199,7 +201,7 @@ function REPL() {
199201 } ;
200202
201203 const executeStreamingCommand = async ( ) => {
202- if ( ! client || ! isConnected || ! commandInput . trim ( ) || isExecuting ) {
204+ if ( ! client || connectionStatus !== "connected" || ! commandInput . trim ( ) || isExecuting ) {
203205 return ;
204206 }
205207
@@ -287,11 +289,13 @@ function REPL() {
287289 < div className = "header" >
288290 < h1 > HTTP REPL</ h1 >
289291 < div
290- className = { `connection-status ${
291- isConnected ? "connected" : "disconnected"
292- } `}
292+ className = { `connection-status ${ connectionStatus } ` }
293293 >
294- { isConnected ? `Connected (${ sessionId } )` : "Disconnected" }
294+ { connectionStatus === "connected"
295+ ? `Connected (${ sessionId } )`
296+ : connectionStatus === "connecting"
297+ ? "Connecting..."
298+ : "Disconnected" }
295299 </ div >
296300 </ div >
297301
@@ -318,7 +322,7 @@ function REPL() {
318322 < button
319323 type = "button"
320324 onClick = { executeStreamingCommand }
321- disabled = { ! isConnected || ! commandInput . trim ( ) || isExecuting }
325+ disabled = { connectionStatus !== "connected" || ! commandInput . trim ( ) || isExecuting }
322326 className = "btn btn-stream"
323327 title = "Execute with real-time streaming output"
324328 >
0 commit comments