Search query / results cards
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user