Skip to content
Snippets Groups Projects
Commit 2ffb5f03 authored by Esko Ikkala's avatar Esko Ikkala
Browse files

Clear suggestions when results update

parent dfc0d036
No related branches found
No related tags found
No related merge requests found
......@@ -75,10 +75,14 @@ const IntegrationAutosuggest = (props) => {
const handleOnChange = (event, { newValue }) => props.updateQuery(newValue);
const handleOnSuggestionSelected = () => props.fetchResults();
const handleOnSuggestionSelected = () => {
props.clearSuggestions();
props.fetchResults();
};
const handleOnKeyDown = (event) => {
if (event.key === 'Enter') {
props.clearSuggestions();
props.fetchResults();
}
};
......
......@@ -35,6 +35,7 @@ const getSuggestionsEpic = (action$, store) => {
const getResultsEpic = (action$, store) => {
const searchUrl = 'http://localhost:3000/search';
return action$.ofType(FETCH_RESULTS)
.debounceTime(500)
.switchMap(() => {
const { query, datasets } = store.getState().search;
if (query.length < 3) {
......
......@@ -27,7 +27,12 @@ const search = (state = INITIAL_STATE, action) => {
return { ...state, suggestions: suggestions(state.suggestions, action) };
case CLEAR_RESULTS:
case UPDATE_RESULTS:
return { ...state, results: results(state.results, action) };
return {
...state,
suggestions: [],
results: results(state.results, action)
};
default:
return state;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment