fix(geocode): replace AbortSignal.timeout with AbortController for compatibility
- AbortSignal.timeout not supported on all mobile browsers - Manual AbortController + setTimeout works everywhere - Fixes location not showing on dashboard and history first point Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -32,10 +32,12 @@
|
||||
if (key === _lastGeoKey) return;
|
||||
_lastGeoKey = key;
|
||||
const fallback = `${lat.toFixed(5)}, ${lon.toFixed(5)}`;
|
||||
fetch(`/api/geocode?lat=${lat}&lon=${lon}`, { signal: AbortSignal.timeout(4000) })
|
||||
.then(r => r.ok ? r.json() : null)
|
||||
const ctrl = new AbortController();
|
||||
const t = setTimeout(() => ctrl.abort(), 6000);
|
||||
fetch(`/api/geocode?lat=${lat}&lon=${lon}`, { signal: ctrl.signal })
|
||||
.then(r => { clearTimeout(t); return r.ok ? r.json() : null; })
|
||||
.then(data => { replayLocation.textContent = (data && data.label) ? data.label : fallback; })
|
||||
.catch(() => { replayLocation.textContent = fallback; });
|
||||
.catch(() => { clearTimeout(t); replayLocation.textContent = fallback; });
|
||||
}
|
||||
|
||||
function scheduleGeocode(lat, lon) {
|
||||
|
||||
+5
-3
@@ -199,10 +199,12 @@ _recenterBtn.addEventListener('click', function () {
|
||||
function reverseGeocode(lat, lon) {
|
||||
const el = document.getElementById('gps-location-name');
|
||||
const fallback = `${lat.toFixed(5)}, ${lon.toFixed(5)}`;
|
||||
fetch(`/api/geocode?lat=${lat}&lon=${lon}`, { signal: AbortSignal.timeout(6000) })
|
||||
.then(r => r.ok ? r.json() : null)
|
||||
const ctrl = new AbortController();
|
||||
const t = setTimeout(() => ctrl.abort(), 6000);
|
||||
fetch(`/api/geocode?lat=${lat}&lon=${lon}`, { signal: ctrl.signal })
|
||||
.then(r => { clearTimeout(t); return r.ok ? r.json() : null; })
|
||||
.then(data => { el.textContent = (data && data.label) ? data.label : fallback; })
|
||||
.catch(() => { el.textContent = fallback; });
|
||||
.catch(() => { clearTimeout(t); el.textContent = fallback; });
|
||||
}
|
||||
|
||||
function _movedEnough(lat, lon) {
|
||||
|
||||
Reference in New Issue
Block a user