From 608b2455983e660095f4836b4c0ccff698100d2f Mon Sep 17 00:00:00 2001 From: Emi Griffith Date: Sat, 11 Jul 2026 07:50:48 -0700 Subject: [PATCH] Compare: resolve a location's name immediately on add MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a lightweight GET /api/v2/place?lat=&lon= endpoint that snaps to the grid cell and returns the reverse-geocoded "neighborhood, city, region" label (the same string the view endpoints expose as place, cached + throttled). On the compare page, adding a location now fires this right away so the chip flips from coordinates to the place name immediately — instead of only resolving when the full comparison loads on Refresh. Best-effort: the series load still resolves the name, so a failed/again call is harmless. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01B3Q2EkHHnTUX2BfhV5q1Zc --- static/compare.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/static/compare.js b/static/compare.js index 001d627..6374e89 100644 --- a/static/compare.js +++ b/static/compare.js @@ -177,11 +177,30 @@ function loadPending(token) { function addLocation(lat, lon) { // Ignore a spot already on the list (same grid neighborhood). if (locations.some((l) => Math.abs(l.lat - lat) < 0.05 && Math.abs(l.lon - lon) < 0.05)) return; - locations.push({ lat, lon, name: null, series: null, loading: false, error: null }); + const loc = { lat, lon, name: null, series: null, loading: false, error: null }; + locations.push(loc); window.Thermograph.saveLastLocation(lat, lon); persistLocations(); writeHashState(); renderAll(); // pending → the Refresh button appears; no fetch until it's tapped + resolveName(loc); // but resolve the neighborhood+city right away (before Refresh) +} + +// Resolve just the place name for a freshly-added location, independent of its +// (deferred, heavier) series load, so the chip flips from coordinates to the +// neighborhood + city immediately on add. Best-effort — the series load resolves +// the name too, so a failure here is harmless. +async function resolveName(loc) { + try { + const res = await fetch(`api/v2/place?lat=${loc.lat}&lon=${loc.lon}`); + if (!res.ok) return; + const d = await res.json(); + // Skip if the location was removed meanwhile, or already got named by a load. + if (!locations.includes(loc) || loc.name || !d || !d.place) return; + loc.name = d.place; + persistLocations(); + renderAll(); + } catch (e) { /* best-effort — the series load will still resolve the name */ } } function removeLocation(i) {