Ron Au commited on
Commit
0ac023f
1 Parent(s): dbeba80

fix(errors): Fix bug on error UI

Browse files
Files changed (2) hide show
  1. static/js/dom-manipulation.js +4 -1
  2. static/js/index.js +13 -12
static/js/dom-manipulation.js CHANGED
@@ -25,7 +25,10 @@ const durationTimer = () => {
25
 
26
  return {
27
  cleanup: (completedTask) => {
28
- updateDuration(completedTask);
 
 
 
29
  clearInterval(incrementSeconds);
30
  window.removeEventListener('focus', updateDuration);
31
  elapsedDisplay.textContent = duration.toFixed(1);
 
25
 
26
  return {
27
  cleanup: (completedTask) => {
28
+ if (completedTask) {
29
+ updateDuration(completedTask);
30
+ }
31
+
32
  clearInterval(incrementSeconds);
33
  window.removeEventListener('focus', updateDuration);
34
  elapsedDisplay.textContent = duration.toFixed(1);
static/js/index.js CHANGED
@@ -22,17 +22,19 @@ const generate = async () => {
22
  return;
23
  }
24
 
25
- try {
26
- const scene = document.querySelector('.scene');
27
- const cardSlot = scene.querySelector('.card-slot');
28
- const actions = document.querySelector('.actions');
29
- const durationDisplay = actions.querySelector('.duration');
30
-
31
- scene.removeEventListener('mousemove', mousemoveHandlerForPreviousCard, true);
32
- cardSlot.innerHTML = '';
33
- generating = true;
34
- setOutput('booster', 'generating');
 
35
 
 
36
  const details = await generateDetails();
37
  pokeName = details.name;
38
  const task = await createTask(details.energy_type);
@@ -41,8 +43,6 @@ const generate = async () => {
41
  actions.setAttribute('aria-hidden', 'false');
42
  actions.querySelectorAll('button').forEach((button) => button.setAttribute('tabindex', '0'));
43
  durationDisplay.classList.add('displayed');
44
- const timer = durationTimer(durationDisplay);
45
- const timerCleanup = timer().cleanup;
46
 
47
  if (window.innerWidth <= 500) {
48
  durationDisplay.scrollIntoView({ behavior: 'smooth' });
@@ -76,6 +76,7 @@ const generate = async () => {
76
  setOutput('card', 'completed');
77
  } catch (err) {
78
  generating = false;
 
79
  setOutput('booster', 'failed');
80
  console.error(err);
81
  }
 
22
  return;
23
  }
24
 
25
+ const scene = document.querySelector('.scene');
26
+ const cardSlot = scene.querySelector('.card-slot');
27
+ const actions = document.querySelector('.actions');
28
+ const durationDisplay = actions.querySelector('.duration');
29
+ const timer = durationTimer(durationDisplay);
30
+ const timerCleanup = timer().cleanup;
31
+
32
+ scene.removeEventListener('mousemove', mousemoveHandlerForPreviousCard, true);
33
+ cardSlot.innerHTML = '';
34
+ generating = true;
35
+ setOutput('booster', 'generating');
36
 
37
+ try {
38
  const details = await generateDetails();
39
  pokeName = details.name;
40
  const task = await createTask(details.energy_type);
 
43
  actions.setAttribute('aria-hidden', 'false');
44
  actions.querySelectorAll('button').forEach((button) => button.setAttribute('tabindex', '0'));
45
  durationDisplay.classList.add('displayed');
 
 
46
 
47
  if (window.innerWidth <= 500) {
48
  durationDisplay.scrollIntoView({ behavior: 'smooth' });
 
76
  setOutput('card', 'completed');
77
  } catch (err) {
78
  generating = false;
79
+ timerCleanup();
80
  setOutput('booster', 'failed');
81
  console.error(err);
82
  }