Skip to content

Commit

Permalink
comments, check userLocation in state first
Browse files Browse the repository at this point in the history
  • Loading branch information
Yen Truong committed Nov 22, 2021
1 parent 5149885 commit f6c937a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions sample-app/src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export default function SearchBar({
const answersActions = useAnswersActions();
const query = useAnswersState(state => state.query.input);
const isLoading = useAnswersState(state => state.searchStatus.isLoading);
/**
* Allow a query search to wait on the response to the autocomplete request right
* before the search execution in order to retrieve the search intents
*/
const responseToLatestRequestRef = useRef<Promise<AutocompleteResponse|undefined>>();
const [ autocompleteResponse, executeAutocomplete] = useAutocomplete(isVertical);

Expand Down
2 changes: 1 addition & 1 deletion sample-app/src/utils/search-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function executeSearchWithIntents(
intents: SearchIntent[],
geolocationOptions?: PositionOptions
) {
if (intents.includes(SearchIntent.NearMe)) {
if (intents.includes(SearchIntent.NearMe) && !answersActions.state.location.userLocation) {
try {
const position = await getUserLocation(geolocationOptions);
answersActions.setUserLocation({
Expand Down

0 comments on commit f6c937a

Please sign in to comment.