Created
November 18, 2016 18:47
-
-
Save Gabri3l/a52fe044c8e5c375c2c8164448922b54 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export const addToFavorites = (item) => ({ | |
type: types.ADD_TO_FAVORITES, | |
item, | |
}); | |
export const removeFromFavorites = (itemIndex) => ({ | |
type: types.REMOVE_FROM_FAVORITES, | |
itemIndex, | |
}); | |
export function addItemToFavorites(item) { | |
const params = { | |
item_id: item.item_id, | |
}; | |
return dispatch => | |
axios.post(api.ADD_ITEM_TO_FAVORITES, params) | |
.then(() => dispatch(addToFavorites(item))) | |
.catch(err => { throw err; }); | |
} | |
export function removeItemFromFavorites(item, itemIndex) { | |
const params = { | |
item_id: item.item_id, | |
}; | |
return dispatch => | |
axios.post(api.REMOVE_ITEM_FROM_FAVORITES, params) | |
.then(() => dispatch(removeItemFromFavorites(itemIndex))) | |
.catch(err => { throw err; }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment