Search query / results cards

This commit is contained in:
2020-07-22 12:45:34 +02:00
parent 2bcbfef8ba
commit d8173a9d7f
14 changed files with 188 additions and 12 deletions

View File

@@ -16,7 +16,9 @@ export const clearAutocomplete = () => {
export const fetchAutocomplete = (input) => {
return function (dispatch) {
axios
.get("http://localhost:4000/search/autocomplete?string=" + input)
.get(
"http://localhost:4000/search/autocomplete?string=" + encodeURI(input)
)
.then((response) => {
const cities = Array.from(response.data.cities);
const restaurants = Array.from(response.data.restaurants);
@@ -30,6 +32,37 @@ export const fetchAutocomplete = (input) => {
};
};
export const fetchSearch = (input) => {
return function (dispatch) {
axios
.get("http://localhost:4000/search?string=" + encodeURI(input))
.then((response) => {
const data = response.data;
if (Object.keys(data).length > 0) {
dispatch(setSearchResults(data));
dispatch(setAppMode("APP_SEARCH_RESULTS"));
}
})
.catch((err) => {
console.log(err);
});
};
};
const setSearchResults = (input) => {
return {
type: "SEARCH_RESULTS",
payload: input,
};
};
export const setSearchQuery = (input) => {
return {
type: "SEARCH_QUERY_SET",
payload: input,
};
};
export const setAppMode = (mode) => {
return {
type: mode,