-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update React Sample App according to new Headless State (#54)
Update React sample app and tests based on the updated headless state - update components to use the new vertical and universal state interfaces, and the new `SearchStatusState` and `QueryState` - update `SearchBar` to manage its own autocomplete results in component state. Added a useAutocomplete hook - Note: autocomplete dropdown will flicker between old and recently trigger search results. This will be address through supporting async and non-async in `inputDropdown` in another item - update `AppliedFilter` and `StaticFilter` to no longer use ID with headless public interface - as discussed with product, any update to static Filter should reset facet to avoid invalid facet send as part of request. Added call to `resetFacets` on `handleFilterOptionChange` J=SLAP-1693 TEST=manual jest tests passed smoke tested sample-app with new headless version - see that universal search executed properly - see that vertical search work with multiple static filters - see that UI for loading state behave properly with universal/vertical search - see that autocomplete display options properly
- Loading branch information
Showing
20 changed files
with
89 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useRef, useState } from "react"; | ||
import { AutocompleteResult, useAnswersActions } from '@yext/answers-headless-react'; | ||
|
||
export function useAutocomplete(isVertical: boolean): [AutocompleteResult[], () => Promise<void>] { | ||
const answersActions = useAnswersActions(); | ||
const autocompleteNetworkIds = useRef({ latestRequest: 0, responseInState: 0 }); | ||
const [ autocompleteResults, setAutocompleteResults ] = useState<AutocompleteResult[]>([]); | ||
async function executeAutocomplete () { | ||
const requestId = ++autocompleteNetworkIds.current.latestRequest; | ||
const response = isVertical | ||
? await answersActions.executeVerticalAutocomplete() | ||
: await answersActions.executeUniversalAutocomplete(); | ||
if (requestId >= autocompleteNetworkIds.current.responseInState) { | ||
setAutocompleteResults(response?.results || []); | ||
autocompleteNetworkIds.current.responseInState = requestId; | ||
} | ||
} | ||
return [ autocompleteResults, executeAutocomplete ] | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.