From ec80766af5e2f59f3842b613f271c1100705af5e Mon Sep 17 00:00:00 2001 From: Mitsuo Tokumori Date: Sat, 8 Mar 2025 01:30:17 +0900 Subject: Change block layout, add time visualization Block layout is now flex. --- static/script.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'static/script.js') diff --git a/static/script.js b/static/script.js index 1cc3e44..f81f9ef 100644 --- a/static/script.js +++ b/static/script.js @@ -1,3 +1,5 @@ +import { initTimeVisualizer } from './timeVisualizer.js'; + let polling = true const blocks = { time: { interval: 30 * 1000, lastUpdate: 0, update: updateTime }, // 30s @@ -9,7 +11,9 @@ let lastPoll = 0; function updateTime() { fetch("/time") .then(res => res.json()) - .then(data => document.getElementById("time").innerText = data.time); + .then(data => { + document.getElementById("weatherSummary").innerText = data.time; + }); } function updateWeather() { @@ -17,9 +21,12 @@ function updateWeather() { fetch(`/weather?city=${encodeURIComponent(city)}`) .then(res => res.json()) .then(data => { - const weatherBlock = document.getElementById("weather"); - if (!data) weatherBlock.innerText = "Error: Bad city"; - else weatherBlock.innerText = `${data.summary}`; + if (!data) { + document.getElementById("weather-summary").innerText = `Error, "${city}" city not found`; + return + } + document.getElementById("weather-summary").innerText = data.summary; + document.getElementById("weather-icon").src = data.icon_url; }); } @@ -54,3 +61,6 @@ reloadAll(); // Poll every 500ms to check intervals (fast enough for 1s updates, light on CPU) // maybe the 1s updates should be special case, but for now let's keep it simple setInterval(pollUpdates, 500); + +// timeVisualizer +initTimeVisualizer('timeVisualizer'); -- cgit v1.2.3