-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
642 additions
and
1,043 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest'; | ||
import { EFAVORITE, EUNKNOWN } from '@shopgate/pwa-core/constants/Pipeline'; | ||
import { shouldFetchData, mutable } from '@shopgate/pwa-common/helpers/redux'; | ||
import { SHOPGATE_USER_GET_FAVORITE_IDS } from '../constants/Pipelines'; | ||
import { requestFavoriteIds, receiveFavoriteIDs, errorFetchFavoriteIds } from '../action-creators'; | ||
import { getFavoritesProducts } from '../selectors'; | ||
|
||
/** | ||
* Fetch favorite IDs action. | ||
* @param {boolean} ignoreCache Ignores cache when true | ||
* @returns {Function} A redux thunk. | ||
*/ | ||
function fetchFavoriteIds(ignoreCache = false) { | ||
return (dispatch, getState) => { | ||
const data = getFavoritesProducts(getState()); | ||
|
||
if (!ignoreCache && !shouldFetchData(data)) { | ||
return Promise.resolve(data); | ||
} | ||
|
||
dispatch(requestFavoriteIds()); | ||
|
||
return new PipelineRequest(SHOPGATE_USER_GET_FAVORITE_IDS) | ||
.setErrorBlacklist([EFAVORITE, EUNKNOWN]) | ||
.dispatch() | ||
.then(({ productIds }) => dispatch(receiveFavoriteIDs(productIds))) | ||
.catch(err => dispatch(errorFetchFavoriteIds(err))); | ||
}; | ||
} | ||
|
||
/** @mixes {MutableFunction} */ | ||
export default mutable(fetchFavoriteIds); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
/** | ||
* @deprecated | ||
*/ | ||
export const SHOPGATE_USER_GET_FAVORITES = 'shopgate.user.getFavorites'; | ||
|
||
export const SHOPGATE_USER_GET_FAVORITE_IDS = 'shopgate.user.getFavoriteIds'; | ||
export const SHOPGATE_USER_ADD_FAVORITES = 'shopgate.user.addFavorites'; | ||
export const SHOPGATE_USER_DELETE_FAVORITES = 'shopgate.user.deleteFavorites'; |
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
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
Oops, something went wrong.