+ autocomplete + thunk
This commit is contained in:
37
src/actions/index.js
Normal file
37
src/actions/index.js
Normal 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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user