Skip to content

Commit

Permalink
use 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 f6c937a commit 8b9fc4c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
12 changes: 8 additions & 4 deletions sample-app/src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import LoadingIndicator from './LoadingIndicator';
import { useAutocomplete } from '../hooks/useAutocomplete';
import { useRef } from 'react';
import { AutocompleteResponse } from '@yext/answers-headless';
import { executeSearchWithIntents } from '../utils/search-operations';
import { executeSearch, executeSearchWithIntents } from '../utils/search-operations';

const SCREENREADER_INSTRUCTIONS = 'When autocomplete results are available, use up and down arrows to review and enter to select.'

Expand Down Expand Up @@ -39,9 +39,13 @@ export default function SearchBar({
const [ autocompleteResponse, executeAutocomplete] = useAutocomplete(isVertical);

async function executeQuery () {
const responseToLatestRequest = await responseToLatestRequestRef.current;
const intents = responseToLatestRequest?.inputIntents || [];
executeSearchWithIntents(answersActions, isVertical, intents, geolocationOptions);
if (answersActions.state.location.userLocation) {
executeSearch(answersActions, isVertical);
} else {
const responseToLatestRequest = await responseToLatestRequestRef.current;
const intents = responseToLatestRequest?.inputIntents || [];
executeSearchWithIntents(answersActions, isVertical, intents, geolocationOptions);
}
}

function renderSearchButton () {
Expand Down
8 changes: 6 additions & 2 deletions sample-app/src/pages/UniversalSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ export default function UniversalSearchPage(props: { universalResultsConfig: Uni
})
answersActions.setVerticalKey('');
const executeQuery = async () => {
const searchIntents = await getSearchIntents(answersActions, false);
executeSearchWithIntents(answersActions, false, searchIntents || []);
if(answersActions.state.location.userLocation) {
answersActions.executeUniversalQuery();
} else {
const searchIntents = await getSearchIntents(answersActions, false);
executeSearchWithIntents(answersActions, false, searchIntents || []);
}
};
executeQuery();
}, [answersActions]);
Expand Down
8 changes: 6 additions & 2 deletions sample-app/src/pages/VerticalSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ export default function VerticalSearchPage(props: {
});
answersActions.setVerticalKey(props.verticalKey);
const executeQuery = async () => {
const searchIntents = await getSearchIntents(answersActions, false);
executeSearchWithIntents(answersActions, true, searchIntents || []);
if(answersActions.state.location.userLocation) {
answersActions.executeVerticalQuery();
} else {
const searchIntents = await getSearchIntents(answersActions, true);
executeSearchWithIntents(answersActions, true, searchIntents || []);
}
};
executeQuery();
}, [answersActions, props.verticalKey]);
Expand Down

0 comments on commit 8b9fc4c

Please sign in to comment.