Merge pull request #30 from griffemi/feat-compare-place-onadd

Compare: resolve location name immediately on add
This commit is contained in:
Emi Griffith 2026-07-11 07:51:21 -07:00 committed by GitHub
commit bec0af3bcf

View file

@ -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) {