Skip to content

Instantly share code, notes, and snippets.

@Gabri3l
Created November 18, 2016 18:47
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 Gabri3l/a52fe044c8e5c375c2c8164448922b54 to your computer and use it in GitHub Desktop.
Save Gabri3l/a52fe044c8e5c375c2c8164448922b54 to your computer and use it in GitHub Desktop.
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