summaryrefslogtreecommitdiff
path: root/app/javascript
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-07-07 20:33:38 -0400
committerDavid Gay <david@davidgay.org>2021-07-07 20:46:27 -0400
commit8c93c5e29eceb9e85cb3eaa7ecc25653ffc50189 (patch)
treeef98cbaed0cf6388a715e79a45b4ee31d637d05a /app/javascript
parentfae9e55c6df3ec9357647a83a3a78319482a284e (diff)
Times of day, and a primitive clock in the header
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/controllers/clock_controller.js29
1 files changed, 29 insertions, 0 deletions
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;
+ });
+ }
+}