+ autocomplete + thunk

This commit is contained in:
2020-07-21 19:39:56 +02:00
parent 29efa13410
commit 2bcbfef8ba
16 changed files with 255 additions and 38 deletions

37
src/actions/index.js Normal file
View File

@@ -0,0 +1,37 @@
import axios from "axios";
const autocomplete = (input) => {
return {
type: "AUTOCOMPLETE_ADD",
payload: input,
};
};
export const clearAutocomplete = () => {
return {
type: "AUTOCOMPLETE_CLEAR",
};
};
export const fetchAutocomplete = (input) => {
return function (dispatch) {
axios
.get("http://localhost:4000/search/autocomplete?string=" + input)
.then((response) => {
const cities = Array.from(response.data.cities);
const restaurants = Array.from(response.data.restaurants);
const options = cities.concat(restaurants);
dispatch(autocomplete(options));
})
.catch((err) => {
console.log(err);
});
};
};
export const setAppMode = (mode) => {
return {
type: mode,
};
};