summaryrefslogtreecommitdiff
path: root/app/javascript/controllers/timer_controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/javascript/controllers/timer_controller.js')
-rw-r--r--app/javascript/controllers/timer_controller.js24
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);