fraudTech commited on
Commit
d39ef07
·
1 Parent(s): 3472614

remove thinking spinner when content starts streaming

Browse files
Files changed (1) hide show
  1. web/src/App.tsx +11 -2
web/src/App.tsx CHANGED
@@ -370,8 +370,9 @@ function App() {
370
  const { done, value } = await reader.read();
371
 
372
  if (done) {
373
- // Stream ended - immediately clear loading state
374
  setIsLoading(false);
 
375
  setStatusMessage('');
376
  break;
377
  }
@@ -396,7 +397,9 @@ function App() {
396
  setStatusMessage(data.message || 'Processing...');
397
  } else if (event === 'content_chunk') {
398
  // Stream content chunks as they arrive
 
399
  setIsLoading(false);
 
400
  setStatusMessage('');
401
 
402
  setMessages((prev) =>
@@ -491,8 +494,8 @@ function App() {
491
  } else if (event === 'response') {
492
  // Final response - this is the definitive completion signal
493
  setIsLoading(false);
494
- setStatusMessage('');
495
  setResponseComplete(true);
 
496
  setMessages((prev) =>
497
  prev.map((msg) =>
498
  msg.id === assistantId
@@ -508,10 +511,12 @@ function App() {
508
  } else if (event === 'done') {
509
  // Stream completed - ensure all loading states are cleared
510
  setIsLoading(false);
 
511
  setStatusMessage('');
512
  } else if (event === 'error') {
513
  // Error occurred
514
  setIsLoading(false);
 
515
  setStatusMessage('');
516
  setMessages((prev) =>
517
  prev.map((msg) =>
@@ -529,6 +534,7 @@ function App() {
529
  } catch (error) {
530
  console.error('Error sending message:', error);
531
  setIsLoading(false);
 
532
  setStatusMessage('');
533
  setMessages((prev) =>
534
  prev.map((msg) =>
@@ -541,7 +547,9 @@ function App() {
541
  )
542
  );
543
  } finally {
 
544
  setIsLoading(false);
 
545
  setStatusMessage('');
546
  }
547
  };
@@ -751,6 +759,7 @@ function App() {
751
  </div>
752
  );
753
  })}
 
754
  {isLoading && !responseComplete && (
755
  <div className="typing-indicator">
756
  <span></span>
 
370
  const { done, value } = await reader.read();
371
 
372
  if (done) {
373
+ // Stream ended - immediately clear ALL loading state
374
  setIsLoading(false);
375
+ setResponseComplete(true);
376
  setStatusMessage('');
377
  break;
378
  }
 
397
  setStatusMessage(data.message || 'Processing...');
398
  } else if (event === 'content_chunk') {
399
  // Stream content chunks as they arrive
400
+ // CRITICAL: Immediately hide spinner when content starts streaming
401
  setIsLoading(false);
402
+ setResponseComplete(true);
403
  setStatusMessage('');
404
 
405
  setMessages((prev) =>
 
494
  } else if (event === 'response') {
495
  // Final response - this is the definitive completion signal
496
  setIsLoading(false);
 
497
  setResponseComplete(true);
498
+ setStatusMessage('');
499
  setMessages((prev) =>
500
  prev.map((msg) =>
501
  msg.id === assistantId
 
511
  } else if (event === 'done') {
512
  // Stream completed - ensure all loading states are cleared
513
  setIsLoading(false);
514
+ setResponseComplete(true);
515
  setStatusMessage('');
516
  } else if (event === 'error') {
517
  // Error occurred
518
  setIsLoading(false);
519
+ setResponseComplete(true);
520
  setStatusMessage('');
521
  setMessages((prev) =>
522
  prev.map((msg) =>
 
534
  } catch (error) {
535
  console.error('Error sending message:', error);
536
  setIsLoading(false);
537
+ setResponseComplete(true);
538
  setStatusMessage('');
539
  setMessages((prev) =>
540
  prev.map((msg) =>
 
547
  )
548
  );
549
  } finally {
550
+ // Final safety net - ensure ALL loading states are cleared
551
  setIsLoading(false);
552
+ setResponseComplete(true);
553
  setStatusMessage('');
554
  }
555
  };
 
759
  </div>
760
  );
761
  })}
762
+ {/* Only show spinner if loading AND response is not complete AND no content yet in the last message */}
763
  {isLoading && !responseComplete && (
764
  <div className="typing-indicator">
765
  <span></span>