diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/javascript/controllers/timer_controller.js | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/app/javascript/controllers/timer_controller.js b/app/javascript/controllers/timer_controller.js index b13188a..30e64cc 100644 --- a/app/javascript/controllers/timer_controller.js +++ b/app/javascript/controllers/timer_controller.js @@ -13,6 +13,7 @@ export default class extends Controller { connect() { if (!this.timerInterval) this.startUpdating(); this.timerTarget.textContent = Math.ceil(this.timeRemainingValue); + this.postFailures = 0; } startUpdating() { @@ -29,15 +30,26 @@ export default class extends Controller { } else { clearInterval(controller.timerInterval); controller.timerInterval = null; - Rails.ajax({ - type: "POST", - url: controller.postUrlValue, - success: () => { - }, - error: () => { - }, - }); + controller.finishActivity(); } }, 10); } + + finishActivity() { + let controller = this; + Rails.ajax({ + type: "POST", + url: controller.postUrlValue, + error: () => { + this.postFailures++; + if (this.postFailures < 5) { + setTimeout(controller.finishActivity, 1000); + } else { + alert("There was an error completing your activity. If your internet connection is otherwise working," + + " please report this issue, mentioning what you were" + + " doing at the time. Check if refreshing the page resolves this issue, and mention that as well."); + } + }, + }); + } } |