Skip to content

Commit a01e5dd

Browse files
committed
harden map geocoding review
1 parent adaf5d6 commit a01e5dd

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/components/LocationSelect/LocationSelect.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,15 @@ async function getAreaNameMatch(
144144
latitude: number
145145
): Promise<AreaNameMatch | null> {
146146
try {
147-
const coordinates = await geocoding.reverse([longitude, latitude]);
147+
const apiKey = process.env.NEXT_PUBLIC_MAPTILER_API_KEY;
148+
149+
if (!apiKey) {
150+
return null;
151+
}
152+
153+
const coordinates = await geocoding.reverse([longitude, latitude], {
154+
apiKey,
155+
});
148156

149157
return getBestAreaNameMatchFromFeatures(
150158
coordinates.features as AreaNameFeature[]
@@ -257,6 +265,9 @@ export default function LocationSelect({
257265
if (nextAreaNameMatch) {
258266
setAreaName(nextAreaNameMatch.name);
259267
inputRef.current?.setQuery(nextAreaNameMatch.name);
268+
} else {
269+
setAreaName("");
270+
inputRef.current?.setQuery("");
260271
}
261272
},
262273
[onLocationInteract, setCoordinates, setAreaName]

src/features/map/components/GeocodingSearch.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ const GeocodingSearch = forwardRef<GeocodingSearchHandle, GeocodingSearchProps>(
275275
onStatusMessageChange?.(statusMessage);
276276
}, [onStatusMessageChange, statusMessage]);
277277

278+
useEffect(() => {
279+
if (activeIndex >= features.length) {
280+
setActiveIndex(0);
281+
}
282+
}, [activeIndex, features.length]);
283+
278284
useImperativeHandle(
279285
forwardedRef,
280286
() => ({

0 commit comments

Comments
 (0)