Skip to content

Commit

Permalink
We should still configure the query endpoint even if the initial auto…
Browse files Browse the repository at this point in the history
…complete query fails before the first search
  • Loading branch information
k-gerner committed Aug 1, 2024
1 parent 4392164 commit 4d45ebc
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/hooks/useSearchWithNearMeHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ export function useSearchWithNearMeHandling(
const searchActions = useSearchActions();

async function executeQuery() {
let intents: SearchIntent[] = [];
if (!searchActions.state.location.userLocation) {
if (!autocompletePromiseRef.current) {
autocompletePromiseRef.current = executeAutocomplete(searchActions);
try {
let intents: SearchIntent[] = [];
if (!searchActions.state.location.userLocation) {
if (!autocompletePromiseRef.current) {
autocompletePromiseRef.current = executeAutocomplete(searchActions);
}
const autocompleteResponseBeforeSearch = await autocompletePromiseRef.current;
intents = autocompleteResponseBeforeSearch?.inputIntents || [];
await updateLocationIfNeeded(searchActions, intents, geolocationOptions);
}
const autocompleteResponseBeforeSearch = await autocompletePromiseRef.current;
intents = autocompleteResponseBeforeSearch?.inputIntents || [];
await updateLocationIfNeeded(searchActions, intents, geolocationOptions);
} catch (e) {
console.error('Error executing autocomplete before search:', e);
await updateLocationIfNeeded(searchActions, [], geolocationOptions);
}
const verticalKey = searchActions.state.vertical.verticalKey ?? '';
const query = searchActions.state.query.input ?? '';
Expand Down

0 comments on commit 4d45ebc

Please sign in to comment.