From 8c93c5e29eceb9e85cb3eaa7ecc25653ffc50189 Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 7 Jul 2021 20:33:38 -0400 Subject: Times of day, and a primitive clock in the header --- app/javascript/controllers/clock_controller.js | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 app/javascript/controllers/clock_controller.js (limited to 'app/javascript/controllers') diff --git a/app/javascript/controllers/clock_controller.js b/app/javascript/controllers/clock_controller.js new file mode 100644 index 0000000..53a1014 --- /dev/null +++ b/app/javascript/controllers/clock_controller.js @@ -0,0 +1,29 @@ +import { Controller } from "stimulus"; + +export default class extends Controller { + static targets = [ "clock" ]; + + static values = { + time: String, + } + + connect() { + this.load(); + let controller = this; + this.clockInterval = setInterval(function() { + controller.load(); + }, 20 * 1000); + } + + disconnect() { + clearInterval(this.clockInterval); + } + + load() { + fetch(`/clock`) + .then(response => response.text()) + .then(html => { + this.clockTarget.innerHTML = html; + }); + } +} -- cgit v1.2.3