Skip to content

Commit

Permalink
Merge pull request #452 from yext/dev/skip-initial-autocomplete-on-fail
Browse files Browse the repository at this point in the history
Gracefully Degrade initial Autocomplete before query
  • Loading branch information
k-gerner authored Aug 1, 2024
2 parents 4392164 + 4d45ebc commit 9b282d9
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 9b282d9

Please sign in to comment.