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:
parent
787cf23395
commit
b156093167
1 changed files with 5 additions and 5 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue