Fix POIs not fetching on map pan

- Fixed sort() mutating enabledCategories array in place (used spread copy)
- Show loading status immediately when a fetch will happen, not after
  the debounce delay
- Reduced debounce to 800ms and min interval to 2s for snappier response

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-04-11 01:39:33 +02:00
parent 787cf23395
commit b156093167
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9

View file

@ -4,8 +4,8 @@ import { getCached, setCached } from "./poi-cache.ts";
import { poiCategories } from "./poi-categories.ts";
const MIN_ZOOM = 12;
const DEBOUNCE_MS = 1000;
const MIN_REQUEST_INTERVAL_MS = 3000;
const DEBOUNCE_MS = 800;
const MIN_REQUEST_INTERVAL_MS = 2000;
const BACKOFF_BASE_MS = 10000;
const MAX_BACKOFF_MS = 60000;
@ -52,7 +52,7 @@ export function usePois(): PoiState {
}
const categories = poiCategories.filter((c) => enabledCategories.includes(c.id));
const categoriesKey = enabledCategories.sort().join(",");
const categoriesKey = [...enabledCategories].sort().join(",");
// Check cache first
const cached = getCached(bbox, categoriesKey);
@ -62,6 +62,8 @@ export function usePois(): PoiState {
return;
}
setStatus("loading");
// Calculate delay: debounce + respect minimum interval
const sinceLastRequest = Date.now() - lastRequestRef.current;
const delay = Math.max(DEBOUNCE_MS, MIN_REQUEST_INTERVAL_MS - sinceLastRequest);
@ -73,8 +75,6 @@ export function usePois(): PoiState {
abortRef.current = controller;
lastRequestRef.current = Date.now();
setStatus("loading");
try {
const result = await queryPois(bbox, categories, controller.signal);
if (controller.signal.aborted) return;