fraudTech commited on
Commit
a0b6810
·
1 Parent(s): 6b95b48

fix spinner state not updating correctly on final response

Browse files
Files changed (1) hide show
  1. web/src/App.tsx +21 -1
web/src/App.tsx CHANGED
@@ -367,7 +367,27 @@ function App() {
367
  while (true) {
368
  const { done, value } = await reader.read();
369
 
370
- if (done) break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
 
372
  buffer += decoder.decode(value, { stream: true });
373
  const lines = buffer.split('\n\n');
 
367
  while (true) {
368
  const { done, value } = await reader.read();
369
 
370
+ if (done) {
371
+ // Process any remaining buffered data before exiting
372
+ if (buffer.trim()) {
373
+ const lines = buffer.split('\n\n');
374
+ for (const line of lines) {
375
+ if (!line.trim()) continue;
376
+ const eventMatch = line.match(/^event: (.+)$/m);
377
+ const dataMatch = line.match(/^data: (.+)$/m);
378
+ if (eventMatch && dataMatch) {
379
+ const event = eventMatch[1];
380
+ const data = JSON.parse(dataMatch[1]);
381
+ // Process the event (especially 'done' event)
382
+ if (event === 'done') {
383
+ setIsLoading(false);
384
+ setStatusMessage('');
385
+ }
386
+ }
387
+ }
388
+ }
389
+ break;
390
+ }
391
 
392
  buffer += decoder.decode(value, { stream: true });
393
  const lines = buffer.split('\n\n');