mirror of
https://github.com/zvx-echo6/navi.git
synced 2026-05-20 22:54:42 +02:00
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:
parent
9db8cec0f6
commit
60effce679
2 changed files with 16 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue