diff --git a/static/app.js b/static/app.js index 19fc983..0dac510 100644 --- a/static/app.js +++ b/static/app.js @@ -1,10 +1,12 @@ "use strict"; +// Shared tier colors, scales, formatters and helpers (single home: shared.js). +const { TIER_COLORS, SCALE_TEMP, drynessColor, ord, esc, todayISO, placeLabel, + fmtPrecip, fmtWind, fmtHumid, locHash } = window.Thermograph; let selected = null; // {lat, lon} const dateInput = document.getElementById("date-input"); const todayBtn = document.getElementById("today-btn"); -const todayISO = () => new Date().toISOString().slice(0, 10); dateInput.value = todayISO(); dateInput.max = dateInput.value; @@ -36,10 +38,8 @@ function selectLocation(lat, lon) { // The Find button opens the shared modal map picker; choosing a spot loads it. const findBtn = document.getElementById("find-btn"); const locLabel = document.getElementById("loc-label"); -findBtn.innerHTML = `${window.LocationPicker.PIN_ICON} Find a location`; -findBtn.addEventListener("click", () => { - window.LocationPicker.open(selected, (lat, lon) => selectLocation(lat, lon)); -}); +window.LocationPicker.initFindButton(findBtn, "Find a location", + () => selected, (lat, lon) => selectLocation(lat, lon)); dateInput.addEventListener("change", () => { syncTodayBtn(); selected && runGrade(); }); @@ -52,7 +52,7 @@ let lastGraded = null; // most recent /api/grade response (for the PNG export) results.addEventListener("click", (e) => { const row = e.target.closest(".rd-grid [data-date]"); if (!row || !selected) return; - location.href = `day#lat=${selected.lat.toFixed(5)}&lon=${selected.lon.toFixed(5)}&date=${row.dataset.date}`; + location.href = `day${locHash(selected.lat, selected.lon, row.dataset.date)}`; }); let gradeSeq = 0; // supersedes an in-flight load when the user picks a new spot/date @@ -95,9 +95,6 @@ async function runGrade() { // Temps flow through the shared unit formatter (°F from the API, shown in the // active unit); the others are unit-agnostic. const fmtTemp = (v) => window.Thermograph.fmtTemp(v); -const fmtPrecip = (v) => (v == null ? "—" : `${v.toFixed(2)}"`); -const fmtWind = (v) => (v == null ? "—" : `${Math.round(v)} mph`); -const fmtHumid = (v) => (v == null ? "—" : `${v.toFixed(1)} g/m³`); // Compact cell formatters for the dense recent/forecast table (units live in the // column headers, so values stay short). Dry days label the running dry streak // (see precipCell) rather than the rain amount. @@ -114,10 +111,6 @@ const IC = { calendar: ``, }; -function placeLabel(data) { - return data.place || `${data.cell.center_lat.toFixed(3)}, ${data.cell.center_lon.toFixed(3)}`; -} - function render(data) { recentData = data; // The place name appears once — as the results heading (