Created
September 16, 2018 02:37
-
-
Save blabadi/12e771ce08bacec6dab611373cc53c84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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