Skip to content

Instantly share code, notes, and snippets.

@blabadi
Created September 16, 2018 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blabadi/12e771ce08bacec6dab611373cc53c84 to your computer and use it in GitHub Desktop.
Save blabadi/12e771ce08bacec6dab611373cc53c84 to your computer and use it in GitHub Desktop.
import {SEARCH_FOOD, RECEIVE_SEARCH_FOOD_RESULTS} from "../actions/searchFoodActions";
const searchFoodResult = (state = { isFetching: false, term: '', results: [] }, action) => {
switch (action.type) {
case SEARCH_FOOD:
return Object.assign({}, state, {
isFetching: true,
term: action.term
});
case RECEIVE_SEARCH_FOOD_RESULTS:
return Object.assign({}, state, {
isFetching: false,
term: action.term,
results: handleSearchFoodResults(action.results)
});
default:
return state
}
};
const handleSearchFoodResults = (results) => {
const searchResults = results.map(food => {
return {
key: food.id,
text: food.name + ", " + food.unit
}
});
return searchResults
}
export default searchFoodResult;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment