coderuday21 commited on
Commit
2b175bf
·
1 Parent(s): 0e5174f

UI: show pseudo progress percentage while analyzing images

Browse files
Files changed (1) hide show
  1. static/js/app.js +46 -0
static/js/app.js CHANGED
@@ -346,6 +346,50 @@ document.getElementById('notify-send-btn')?.addEventListener('click', async () =
346
  });
347
 
348
  // ---- Run detection ----
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
  document.getElementById('form-detect')?.addEventListener('submit', async (e) => {
350
  e.preventDefault();
351
  hideError('dashboard-error');
@@ -360,6 +404,7 @@ document.getElementById('form-detect')?.addEventListener('submit', async (e) =>
360
  const loading = document.getElementById('run-loading');
361
  btn.disabled = true;
362
  loading.classList.remove('hidden');
 
363
 
364
  const token = getToken();
365
  const form = new FormData();
@@ -411,6 +456,7 @@ document.getElementById('form-detect')?.addEventListener('submit', async (e) =>
411
  } finally {
412
  btn.disabled = false;
413
  loading.classList.add('hidden');
 
414
  }
415
  });
416
 
 
346
  });
347
 
348
  // ---- Run detection ----
349
+ let _detectProgressTimer = null;
350
+ let _detectProgressValue = 0;
351
+
352
+ function startDetectionProgress() {
353
+ const loading = document.getElementById('run-loading');
354
+ if (!loading) return;
355
+ _detectProgressValue = 0;
356
+ loading.querySelector('.spinner')?.classList.remove('hidden');
357
+ function updateLabel() {
358
+ const pct = Math.min(99, Math.max(1, Math.round(_detectProgressValue)));
359
+ loading.childNodes.forEach((n) => {
360
+ if (n.nodeType === Node.TEXT_NODE) {
361
+ n.textContent = ` Analyzing images... ${pct}%`;
362
+ }
363
+ });
364
+ }
365
+ updateLabel();
366
+ if (_detectProgressTimer) clearInterval(_detectProgressTimer);
367
+ _detectProgressTimer = setInterval(() => {
368
+ // Ease out: slow down as it approaches 95%
369
+ if (_detectProgressValue < 95) {
370
+ _detectProgressValue += Math.max(0.5, (100 - _detectProgressValue) * 0.03);
371
+ updateLabel();
372
+ }
373
+ }, 400);
374
+ }
375
+
376
+ function stopDetectionProgress(success) {
377
+ const loading = document.getElementById('run-loading');
378
+ if (_detectProgressTimer) {
379
+ clearInterval(_detectProgressTimer);
380
+ _detectProgressTimer = null;
381
+ }
382
+ if (!loading) return;
383
+ if (success) {
384
+ _detectProgressValue = 100;
385
+ loading.childNodes.forEach((n) => {
386
+ if (n.nodeType === Node.TEXT_NODE) {
387
+ n.textContent = ' Analyzing images... 100%';
388
+ }
389
+ });
390
+ }
391
+ }
392
+
393
  document.getElementById('form-detect')?.addEventListener('submit', async (e) => {
394
  e.preventDefault();
395
  hideError('dashboard-error');
 
404
  const loading = document.getElementById('run-loading');
405
  btn.disabled = true;
406
  loading.classList.remove('hidden');
407
+ startDetectionProgress();
408
 
409
  const token = getToken();
410
  const form = new FormData();
 
456
  } finally {
457
  btn.disabled = false;
458
  loading.classList.add('hidden');
459
+ stopDetectionProgress(true);
460
  }
461
  });
462