From d9af103b9a8aed86d6ac834f1240edfb2173ffa0 Mon Sep 17 00:00:00 2001 From: Mitsuo Tokumori Date: Sat, 8 Mar 2025 02:17:52 +0900 Subject: 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) --- static/block_weather.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 static/block_weather.js (limited to 'static/block_weather.js') 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; + }); +} + -- cgit v1.2.3