From 9fec79398a34d26be1042e35cae429b88f8b96d0 Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 19 May 2021 18:39:35 -0400 Subject: Revise and progress with hearth amenity construction --- .../controllers/activities/timer_controller.js | 43 --------------------- app/javascript/controllers/timer_controller.js | 44 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 43 deletions(-) delete mode 100644 app/javascript/controllers/activities/timer_controller.js create mode 100644 app/javascript/controllers/timer_controller.js (limited to 'app/javascript') diff --git a/app/javascript/controllers/activities/timer_controller.js b/app/javascript/controllers/activities/timer_controller.js deleted file mode 100644 index 11057c0..0000000 --- a/app/javascript/controllers/activities/timer_controller.js +++ /dev/null @@ -1,43 +0,0 @@ -import { Controller } from "stimulus"; -import Rails from "@rails/ujs"; - -export default class extends Controller { - static targets = [ "timer" ]; - - static values = { - start: Number, - } - - initialize() { - this.counter = this.startValue; - this.timerTarget.textContent = this.counter; - } - - connect() { - this.startUpdating(); - } - - disconnect() { - this.stopUpdating(); - } - - startUpdating() { - this.timerInterval = setInterval(() => { - if (this.counter > 0) { - this.timerTarget.textContent = this.counter.toString(); - this.counter--; - } else if (this.counter === 0) { - Rails.ajax({ - type: "POST", - url: "/finish_activity", - }); - } - }, 1000); - } - - stopUpdating() { - if (this.timerInterval) { - clearInterval(this.timerInterval); - } - } -} diff --git a/app/javascript/controllers/timer_controller.js b/app/javascript/controllers/timer_controller.js new file mode 100644 index 0000000..7714bad --- /dev/null +++ b/app/javascript/controllers/timer_controller.js @@ -0,0 +1,44 @@ +import { Controller } from "stimulus"; +import Rails from "@rails/ujs"; + +export default class extends Controller { + static targets = [ "timer" ]; + + static values = { + start: Number, + postUrl: String, + } + + initialize() { + this.counter = this.startValue; + this.timerTarget.textContent = this.counter; + } + + connect() { + this.startUpdating(); + } + + disconnect() { + this.stopUpdating(); + } + + startUpdating() { + this.timerInterval = setInterval(() => { + if (this.counter > 0) { + this.timerTarget.textContent = this.counter.toString(); + this.counter--; + } else if (this.counter === 0) { + Rails.ajax({ + type: "POST", + url: this.postUrlValue, + }); + } + }, 1000); + } + + stopUpdating() { + if (this.timerInterval) { + clearInterval(this.timerInterval); + } + } +} -- cgit v1.2.3