Repository navigation
Search for a place instead of only nearby ones - #18
Merged
Merged
Conversation
The place step only ever offered the places iNaturalist returns for the browser's geolocation, so there was no way to study somewhere you aren't. This adds a search box backed by iNaturalist's place autocomplete endpoint. An empty box keeps showing the nearby places, so search is an alternative to the location-based suggestions rather than a step in front of them. Typing replaces the list with matches, and clearing it brings the nearby places back. Selecting a searched place feeds the same PLACE_SELECTED action, so the rest of the flow is unchanged. Queries are debounced, and a query that changes while a request is still in flight aborts it — otherwise a slow response for an earlier prefix could land after a newer one and overwrite it. Two supporting changes: - `geometry_geojson` on `Place` is now optional. The autocomplete endpoint is not documented to return geometry for every hit, and the map preview is the only thing that needs it, so a place without geometry renders as a card with no map rather than an empty map of the Atlantic. - `apiV1Fetch` now rejects on a non-2xx response and accepts an `AbortSignal`. It previously read `results` off an error body and handed back `undefined`, which gave the new error state nothing to trigger on. Place cards are now keyed by place id rather than list index. Leaflet only initializes a map on mount, so with index keys a searched place would have reused the previous place's map. Verified in a browser against the offline fixture: nearby places show with an empty box, a matching query swaps the list, a non-matching one shows the empty state, clearing restores the nearby list, and selecting a searched place advances to the taxa step with the place in the navbar. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J7nU5T9UJU7ydrRdENiKuQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The place step only ever offered the places iNaturalist returns for the browser's geolocation, so there was no way to study somewhere you aren't. This adds a search box on that step, backed by iNaturalist's place autocomplete endpoint.
Behaviour
An empty box keeps showing the nearby places, so search is an alternative to the location-based suggestions rather than a step in front of them:
fakeNo places found matching “…”.Could not search for places. Check your connection and try again.Clearing the box brings the nearby places back. Selecting a searched place dispatches the same
PLACE_SELECTEDaction, so nothing downstream changes.Queries are debounced (300ms), and a query that changes while a request is in flight aborts it — otherwise a slow response for an earlier prefix could land after a newer one and overwrite it.
Supporting changes
geometry_geojsononPlaceis now optional. The autocomplete endpoint isn't documented to return geometry for every hit, and the map preview is the only thing that needs it. A place without geometry now renders as a card with no map, rather than an empty map of the Atlantic. The nearby path is unaffected.apiV1Fetchrejects on a non-2xx response and accepts anAbortSignal. It previously readresultsoff an error body and handed backundefined, which gave the new error state nothing to trigger on.Verification
npm run lint,npx jest --config=configs/jest.jsonandnpm run buildall pass.Driven in a real browser (Playwright, against the offline fixture since this sandbox can't reach
api.inaturalist.org):No page errors or React exceptions in any step.
Two things worth flagging
api.inaturalist.org, so the live request path is unverified against the actual API. The one assumption it rests on is that autocomplete results carryidanddisplay_name—idis all the rest of the flow needs. I made geometry optional rather than assume it's present.LocationStepto succeed, so someone who denies location can't get to the search at all — and that error path is currently a no-op expression that renders nothing. Letting the user skip straight to search is the natural follow-up, but it changes the app's step machine, so I left it out. Happy to do it if you want.🤖 Generated with Claude Code
https://claude.ai/code/session_01J7nU5T9UJU7ydrRdENiKuQ
Generated by Claude Code