fix: search geocode now includes viewport bias in API requests

Symptom: HAR capture showed /api/geocode requests with NO lat/lon/zoom
params despite map being centered on Twin Falls. Results returned
out-of-state addresses (Illinois, Iowa, Arkansas).

Root cause: SearchBar subscribed to mapCenter via React hook, but the
value was stale at search time due to render timing.

Fix: api.js searchGeocode now reads mapCenter directly from the store
via useStore.getState() at call time. This is the correct pattern for
non-component code. SearchBar no longer passes mapCenter as a param.
This commit is contained in:
Matt 2026-04-26 23:38:31 +00:00
commit 60effce679
2 changed files with 16 additions and 6 deletions

View file

@ -53,7 +53,7 @@ const SearchBar = forwardRef(function SearchBar(_, ref) {
const setClickMarker = useStore((s) => s.setClickMarker)
const setEditingContact = useStore((s) => s.setEditingContact)
const clearPendingDestination = useStore((s) => s.clearPendingDestination)
const mapCenter = useStore((s) => s.mapCenter)
// mapCenter now read directly in api.js
useEffect(() => {
inputRef.current?.focus()
@ -100,7 +100,7 @@ const SearchBar = forwardRef(function SearchBar(_, ref) {
setSearchLoading(true)
try {
const data = await searchGeocode(q.trim(), 6, ctrl.signal, mapCenter)
const data = await searchGeocode(q.trim(), 6, ctrl.signal)
const combined = [...contactResults, ...(data.results || [])]
setResults(combined)
setAutocompleteOpen(combined.length > 0)