diff options
author | David Gay <david@davidgay.org> | 2021-05-27 19:24:12 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-05-27 19:24:12 -0400 |
commit | 09dbf09b5fa6d106a57cdb601c6ed6c23e00f7dd (patch) | |
tree | 26ff703ba99ef0821f0f74539378e40e18dd85af /app/javascript/controllers | |
parent | d9f829e7a723ae36367280950dcbb7edf394e9a2 (diff) |
Make timer more robust, and `stop_activity` if you can't do it
Diffstat (limited to 'app/javascript/controllers')
-rw-r--r-- | app/javascript/controllers/timer_controller.js | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/app/javascript/controllers/timer_controller.js b/app/javascript/controllers/timer_controller.js index 7714bad..5190a79 100644 --- a/app/javascript/controllers/timer_controller.js +++ b/app/javascript/controllers/timer_controller.js @@ -12,6 +12,7 @@ export default class extends Controller { initialize() { this.counter = this.startValue; this.timerTarget.textContent = this.counter; + this.postFailures = 0; } connect() { @@ -23,14 +24,27 @@ export default class extends Controller { } startUpdating() { + let controller = this; this.timerInterval = setInterval(() => { - if (this.counter > 0) { - this.timerTarget.textContent = this.counter.toString(); - this.counter--; - } else if (this.counter === 0) { + if (controller.postFailures >= 5) { + alert("An error occurred. Please submit a bug report, explaining what you were doing when it occurred."); + clearInterval(controller.timerInterval); + return; + } + + if (controller.counter > 0) { + controller.timerTarget.textContent = controller.counter.toString(); + controller.counter--; + } else if (this.counter <= 0) { Rails.ajax({ type: "POST", - url: this.postUrlValue, + url: controller.postUrlValue, + success: () => { + controller.postFailures = 0; + }, + error: () => { + controller.postFailures++; + }, }); } }, 1000); |