summaryrefslogtreecommitdiff
path: root/app/javascript/controllers/activities/timer_controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/javascript/controllers/activities/timer_controller.js')
-rw-r--r--app/javascript/controllers/activities/timer_controller.js43
1 files changed, 0 insertions, 43 deletions
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);
- }
- }
-}