aboutsummaryrefslogtreecommitdiffstats
path: root/static/block_weather.js
diff options
context:
space:
mode:
authorMitsuo Tokumori <[email protected]>2025-03-08 02:17:52 +0900
committerMitsuo Tokumori <[email protected]>2025-03-08 02:17:52 +0900
commitd9af103b9a8aed86d6ac834f1240edfb2173ffa0 (patch)
tree6b11b47db6201a357277b587561fb429c2451b99 /static/block_weather.js
parentec80766af5e2f59f3842b613f271c1100705af5e (diff)
downloadmasu-d9af103b9a8aed86d6ac834f1240edfb2173ffa0.tar.gz
masu-d9af103b9a8aed86d6ac834f1240edfb2173ffa0.tar.bz2
masu-d9af103b9a8aed86d6ac834f1240edfb2173ffa0.zip
Restructure js and css into single block modules
Each block is defined by: * html: front-end elements (modify: templates/index.html) (for now) * css: front-end design (modify: static/style.css) * js: front-end code (new file: static/block_name.js) * python: back-end code (new file: ./block_name.py) (will move later from the root to an "app" directory (python package)
Diffstat (limited to 'static/block_weather.js')
-rw-r--r--static/block_weather.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/static/block_weather.js b/static/block_weather.js
new file mode 100644
index 0000000..4ae6d2d
--- /dev/null
+++ b/static/block_weather.js
@@ -0,0 +1,14 @@
+export function updateWeather() {
+ const city = document.getElementById("city").value;
+ fetch(`/weather?city=${encodeURIComponent(city)}`)
+ .then(res => res.json())
+ .then(data => {
+ 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;
+ });
+}
+