@shopgate/pwa-common-commerce 7.30.0-alpha.7 → 7.30.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cart/action-creators/addCouponsToCart.js +9 -2
- package/cart/action-creators/addProductsToCart.js +9 -2
- package/cart/action-creators/deleteCouponsFromCart.js +9 -2
- package/cart/action-creators/deleteProductsFromCart.js +9 -2
- package/cart/action-creators/errorAddCouponsToCart.js +10 -2
- package/cart/action-creators/errorAddProductsToCart.js +10 -2
- package/cart/action-creators/errorCart.js +8 -2
- package/cart/action-creators/errorDeleteCouponsFromCart.js +10 -2
- package/cart/action-creators/errorDeleteProductsFromCart.js +10 -2
- package/cart/action-creators/errorUpdateProductsInCart.js +10 -2
- package/cart/action-creators/receiveCart.js +9 -2
- package/cart/action-creators/requestCart.js +8 -2
- package/cart/action-creators/setCartProductPendingCount.js +9 -2
- package/cart/action-creators/setCouponFieldError.js +9 -2
- package/cart/action-creators/setCouponFieldValue.js +9 -2
- package/cart/action-creators/setFulfillmentSlot.js +9 -2
- package/cart/action-creators/successAddCouponsToCart.js +10 -2
- package/cart/action-creators/successAddProductsToCart.js +8 -2
- package/cart/action-creators/successDeleteCouponsFromCart.js +8 -2
- package/cart/action-creators/successDeleteProductsFromCart.js +8 -2
- package/cart/action-creators/successUpdateProductsInCart.js +8 -2
- package/cart/action-creators/updateProductsInCart.js +9 -2
- package/cart/actions/addCouponsToCart.js +52 -8
- package/cart/actions/addProductsToCart.js +80 -11
- package/cart/actions/deleteCouponsFromCart.js +39 -6
- package/cart/actions/deleteProductsFromCart.js +38 -6
- package/cart/actions/fetchCart.js +52 -8
- package/cart/actions/updateProductsInCart.js +44 -6
- package/cart/constants/PipelineErrors.js +6 -1
- package/cart/constants/Pipelines.js +6 -1
- package/cart/constants/Portals.js +85 -1
- package/cart/constants/index.js +39 -2
- package/cart/helpers/config.js +47 -2
- package/cart/helpers/createPipelineErrorList.js +30 -4
- package/cart/helpers/fulfillmentSlots.js +37 -4
- package/cart/helpers/index.js +14 -3
- package/cart/helpers/quantity.js +23 -4
- package/cart/helpers/shipping.js +57 -2
- package/cart/helpers/tax.js +26 -2
- package/cart/index.js +25 -5
- package/cart/mock.js +130 -1
- package/cart/reducers/couponField.js +30 -2
- package/cart/reducers/data.js +98 -6
- package/cart/reducers/index.js +7 -1
- package/cart/selectors/index.js +181 -31
- package/cart/selectors/spec.js +189 -2
- package/cart/streams/index.js +176 -29
- package/cart/subscriptions/index.js +307 -30
- package/category/action-creators/errorCategory.js +10 -2
- package/category/action-creators/errorCategoryChildren.js +9 -2
- package/category/action-creators/errorRootCategories.js +8 -2
- package/category/action-creators/receiveCategory.js +12 -2
- package/category/action-creators/receiveCategoryChildren.js +10 -2
- package/category/action-creators/receiveRootCategories.js +9 -2
- package/category/action-creators/requestCategory.js +9 -2
- package/category/action-creators/requestCategoryChildren.js +9 -2
- package/category/action-creators/requestRootCategories.js +8 -2
- package/category/actions/fetchCategory.js +47 -5
- package/category/actions/fetchCategoryChildren.js +30 -2
- package/category/actions/fetchCategoryOrRootCategories.js +16 -2
- package/category/actions/fetchCategoryProducts.js +36 -2
- package/category/actions/fetchRootCategories.js +31 -2
- package/category/actions/getCategory.js +10 -2
- package/category/constants/Pipelines.js +3 -1
- package/category/constants/Portals.js +56 -3
- package/category/constants/index.js +17 -2
- package/category/helpers/index.js +27 -3
- package/category/index.js +19 -5
- package/category/mock.js +176 -1
- package/category/reducers/categoriesById.js +65 -3
- package/category/reducers/childrenByCategoryId.js +55 -4
- package/category/reducers/helpers/handleCategoryCollection.js +24 -3
- package/category/reducers/helpers/handleReceivedCategories.js +3 -1
- package/category/reducers/index.js +12 -2
- package/category/reducers/rootCategories.js +31 -2
- package/category/selectors/index.js +115 -16
- package/category/streams/index.js +82 -4
- package/category/subscriptions/index.js +96 -3
- package/checkout/action-creators/successCheckout.js +9 -2
- package/checkout/actions/fetchCheckoutUrl.js +28 -3
- package/checkout/constants/Pipelines.js +1 -1
- package/checkout/constants/index.js +3 -2
- package/checkout/index.js +11 -4
- package/checkout/selectors/index.js +7 -2
- package/checkout/streams/index.js +8 -2
- package/checkout/subscriptions/index.js +35 -6
- package/favorites/action-creators/index.js +206 -24
- package/favorites/actions/addFavorites.js +41 -3
- package/favorites/actions/addFavoritesList.js +27 -2
- package/favorites/actions/fetchFavoriteIds.js +49 -5
- package/favorites/actions/fetchFavorites.js +60 -5
- package/favorites/actions/fetchFavoritesList.js +47 -3
- package/favorites/actions/fetchFavoritesListsWithItems.js +32 -3
- package/favorites/actions/getFavorites.js +6 -2
- package/favorites/actions/removeFavorites.js +32 -3
- package/favorites/actions/removeFavoritesList.js +24 -2
- package/favorites/actions/toggleFavorites.js +68 -10
- package/favorites/actions/updateFavorites.js +39 -3
- package/favorites/actions/updateFavoritesList.js +26 -2
- package/favorites/constants/Pipelines.js +9 -1
- package/favorites/constants/Portals.js +32 -4
- package/favorites/constants/index.js +37 -5
- package/favorites/index.js +14 -4
- package/favorites/mock.js +89 -4
- package/favorites/reducers/index.js +7 -1
- package/favorites/reducers/lists.js +74 -2
- package/favorites/reducers/products.js +231 -24
- package/favorites/selectors/index.js +188 -24
- package/favorites/streams/index.js +135 -23
- package/favorites/streams/spec.js +517 -8
- package/favorites/subscriptions/index.js +260 -25
- package/favorites/subscriptions/spec.js +700 -28
- package/filter/action-creators/errorFilters.js +9 -2
- package/filter/action-creators/index.js +4 -1
- package/filter/action-creators/receiveFilters.js +10 -2
- package/filter/action-creators/requestFilters.js +9 -2
- package/filter/action-creators/updateFilters.js +8 -2
- package/filter/actions/fetchFilters.js +46 -3
- package/filter/actions/getFilters.js +6 -2
- package/filter/actions/helpers/buildFilterParams.js +34 -2
- package/filter/actions/helpers/buildRequestFilters.js +35 -2
- package/filter/actions/helpers/processFilters.js +10 -2
- package/filter/actions/helpers/processParams.js +26 -2
- package/filter/constants/Pipelines.js +1 -1
- package/filter/constants/Portals.js +39 -3
- package/filter/constants/index.js +8 -1
- package/filter/index.js +12 -4
- package/filter/reducers/helpers/enrichFilters.js +11 -3
- package/filter/reducers/index.js +5 -1
- package/filter/reducers/resultsByHash.js +43 -3
- package/filter/selectors/index.js +47 -6
- package/filter/streams/index.js +30 -1
- package/filter/subscriptions/index.js +34 -2
- package/market/constants/Portals.js +22 -4
- package/market/constants/index.js +2 -1
- package/market/helpers/showReturnPolicy.js +3 -1
- package/market/helpers/showTaxDisclaimer.js +3 -1
- package/market/index.js +6 -2
- package/orders/constants.js +2 -1
- package/package.json +4 -4
- package/product/action-creators/deleteProductsByIds.js +10 -2
- package/product/action-creators/errorProduct.js +10 -2
- package/product/action-creators/errorProductDescription.js +10 -2
- package/product/action-creators/errorProductImages.js +10 -2
- package/product/action-creators/errorProductMedia.js +10 -2
- package/product/action-creators/errorProductOptions.js +10 -2
- package/product/action-creators/errorProductProperties.js +10 -2
- package/product/action-creators/errorProductRelations.js +9 -2
- package/product/action-creators/errorProductShipping.js +10 -2
- package/product/action-creators/errorProductVariants.js +10 -2
- package/product/action-creators/errorProducts.js +9 -2
- package/product/action-creators/expireProductById.js +10 -2
- package/product/action-creators/expireProductData.js +11 -2
- package/product/action-creators/expireProductsByHash.js +9 -2
- package/product/action-creators/productNotAvailable.js +10 -2
- package/product/action-creators/provideProduct.js +9 -2
- package/product/action-creators/receiveProduct.js +10 -2
- package/product/action-creators/receiveProductCached.js +9 -2
- package/product/action-creators/receiveProductDescription.js +10 -2
- package/product/action-creators/receiveProductImages.js +10 -2
- package/product/action-creators/receiveProductMedia.js +10 -2
- package/product/action-creators/receiveProductOptions.js +10 -2
- package/product/action-creators/receiveProductProperties.js +10 -2
- package/product/action-creators/receiveProductRelations.js +12 -2
- package/product/action-creators/receiveProductShipping.js +10 -2
- package/product/action-creators/receiveProductVariants.js +10 -2
- package/product/action-creators/receiveProducts.js +16 -2
- package/product/action-creators/receiveProductsCached.js +9 -2
- package/product/action-creators/refreshExpiredPDPData.js +8 -2
- package/product/action-creators/requestProduct.js +10 -2
- package/product/action-creators/requestProductDescription.js +9 -2
- package/product/action-creators/requestProductImages.js +9 -2
- package/product/action-creators/requestProductMedia.js +9 -2
- package/product/action-creators/requestProductOptions.js +9 -2
- package/product/action-creators/requestProductProperties.js +9 -2
- package/product/action-creators/requestProductRelations.js +10 -2
- package/product/action-creators/requestProductShipping.js +9 -2
- package/product/action-creators/requestProductVariants.js +9 -2
- package/product/action-creators/requestProducts.js +9 -2
- package/product/action-creators/setProductId.js +9 -2
- package/product/action-creators/setProductQuantity.js +9 -2
- package/product/action-creators/setProductVariantId.js +9 -2
- package/product/actions/changeSortOrder.js +21 -2
- package/product/actions/fetchHighlightProducts.js +18 -2
- package/product/actions/fetchLiveshoppingProducts.js +14 -2
- package/product/actions/fetchProduct.js +52 -3
- package/product/actions/fetchProductDescription.js +30 -2
- package/product/actions/fetchProductImages.js +31 -2
- package/product/actions/fetchProductMedia.js +35 -2
- package/product/actions/fetchProductOptions.js +31 -2
- package/product/actions/fetchProductProperties.js +30 -2
- package/product/actions/fetchProductRelations.js +63 -2
- package/product/actions/fetchProductShipping.js +31 -2
- package/product/actions/fetchProductVariants.js +31 -2
- package/product/actions/fetchProducts.js +189 -17
- package/product/actions/fetchProductsById.js +68 -8
- package/product/actions/fetchProductsByQuery.js +102 -18
- package/product/actions/getHighlightProducts.js +6 -2
- package/product/actions/getLiveshoppingProducts.js +6 -2
- package/product/actions/getProduct.js +6 -2
- package/product/actions/getProductDescription.js +6 -2
- package/product/actions/getProductImages.js +6 -2
- package/product/actions/getProductOptions.js +6 -2
- package/product/actions/getProductProperties.js +6 -2
- package/product/actions/getProductRelations.js +6 -2
- package/product/actions/getProductShipping.js +6 -2
- package/product/actions/getProductVariants.js +6 -2
- package/product/actions/getProducts.js +6 -2
- package/product/actions/getProductsById.js +6 -2
- package/product/actions/getProductsByQuery.js +6 -2
- package/product/actions/processProductFlags.js +35 -3
- package/product/actions/updateMetadata.js +17 -2
- package/product/collections/ProductImageFormats.js +48 -8
- package/product/collections/index.js +1 -1
- package/product/constants/Pipelines.js +12 -1
- package/product/constants/Portals.js +200 -33
- package/product/constants/index.js +90 -18
- package/product/helpers/index.js +61 -8
- package/product/index.js +36 -6
- package/product/mock.js +1002 -2
- package/product/reducers/descriptionsByProductId.js +54 -5
- package/product/reducers/helpers/formatOptions.js +17 -2
- package/product/reducers/helpers/handleProductCollection.js +19 -2
- package/product/reducers/imagesByProductId.js +51 -4
- package/product/reducers/index.js +23 -1
- package/product/reducers/mediaByProductId.js +55 -3
- package/product/reducers/optionsByProductId.js +41 -2
- package/product/reducers/productRelationsByHash.js +43 -2
- package/product/reducers/productsById.js +122 -7
- package/product/reducers/propertiesByProductId.js +48 -2
- package/product/reducers/resultsByHash.js +125 -9
- package/product/reducers/shippingByProductId.js +37 -2
- package/product/reducers/variantsByProductId.js +56 -2
- package/product/selectors/options.js +90 -13
- package/product/selectors/page.js +62 -13
- package/product/selectors/price.js +81 -18
- package/product/selectors/product.js +549 -59
- package/product/selectors/product.mock.js +327 -12
- package/product/selectors/relations.js +35 -5
- package/product/selectors/variants.js +91 -15
- package/product/streams/index.js +167 -13
- package/product/subscriptions/index.js +210 -4
- package/reviews/action-creators/errorProductReviews.js +9 -2
- package/reviews/action-creators/errorReviews.js +9 -2
- package/reviews/action-creators/errorSubmitReview.js +9 -2
- package/reviews/action-creators/errorUserReview.js +9 -2
- package/reviews/action-creators/flushUserReview.js +8 -2
- package/reviews/action-creators/receiveProductReviews.js +11 -2
- package/reviews/action-creators/receiveReviews.js +12 -2
- package/reviews/action-creators/receiveSubmitReview.js +9 -2
- package/reviews/action-creators/receiveUserReview.js +10 -2
- package/reviews/action-creators/requestProductReviews.js +10 -2
- package/reviews/action-creators/requestReviews.js +9 -2
- package/reviews/action-creators/requestSubmitReview.js +9 -2
- package/reviews/action-creators/requestUserReview.js +9 -2
- package/reviews/action-creators/resetSubmittedReview.js +9 -2
- package/reviews/action-creators/spec.js +40 -1
- package/reviews/actions/fetchProductReviews.js +37 -2
- package/reviews/actions/fetchReviews.js +38 -2
- package/reviews/actions/fetchUserReview.js +31 -2
- package/reviews/actions/flushUserReview.js +5 -1
- package/reviews/actions/getProductReviews.js +6 -2
- package/reviews/actions/getUserReview.js +6 -2
- package/reviews/actions/spec.js +241 -4
- package/reviews/actions/submitReview.js +63 -3
- package/reviews/constants/Pipelines.js +4 -1
- package/reviews/constants/Portals.js +4 -1
- package/reviews/constants/index.js +26 -7
- package/reviews/index.js +15 -4
- package/reviews/mock.js +172 -11
- package/reviews/reducers/index.js +11 -1
- package/reviews/reducers/mock.js +14 -2
- package/reviews/reducers/reviewsByHash.js +52 -6
- package/reviews/reducers/reviewsById.js +27 -2
- package/reviews/reducers/reviewsByProductId.js +47 -2
- package/reviews/reducers/spec.js +211 -2
- package/reviews/reducers/userReviewsByProductId.js +68 -2
- package/reviews/selectors/index.js +123 -19
- package/reviews/selectors/mock.js +100 -1
- package/reviews/selectors/spec.js +100 -1
- package/reviews/streams/index.js +37 -5
- package/reviews/streams/spec.js +25 -1
- package/reviews/subscriptions/index.js +27 -2
- package/scanner/action-creators/errorHandleScanner.js +11 -2
- package/scanner/action-creators/scannerFinished.js +11 -2
- package/scanner/action-creators/startScanner.js +8 -2
- package/scanner/action-creators/successHandleScanner.js +11 -2
- package/scanner/actions/handleBarCode.js +22 -2
- package/scanner/actions/handleNoResults.js +23 -2
- package/scanner/actions/handleQrCode.js +116 -6
- package/scanner/actions/handleSearch.js +33 -2
- package/scanner/constants/Portals.js +22 -1
- package/scanner/constants/index.js +17 -1
- package/scanner/helpers/index.js +115 -5
- package/scanner/index.js +19 -5
- package/scanner/streams/index.js +36 -1
- package/scanner/subscriptions/index.js +78 -8
- package/search/action-creators/errorSearchResults.js +10 -2
- package/search/action-creators/receiveSearchResults.js +11 -2
- package/search/action-creators/receiveSearchSuggestions.js +10 -2
- package/search/action-creators/requestSearchResults.js +10 -2
- package/search/action-creators/requestSearchSuggestions.js +9 -2
- package/search/actions/fetchSearchResults.js +66 -8
- package/search/actions/fetchSearchSuggestions.js +36 -2
- package/search/constants/Pipelines.js +1 -1
- package/search/constants/Portals.js +9 -2
- package/search/constants/index.js +10 -2
- package/search/helpers/index.js +5 -2
- package/search/helpers/removeHighlightingPlaceholders.js +4 -1
- package/search/helpers/spec.js +19 -1
- package/search/index.js +17 -5
- package/search/reducers/index.js +38 -2
- package/search/selectors/index.js +23 -4
- package/search/streams/index.js +51 -3
- package/search/subscriptions/index.js +132 -5
|
@@ -1,31 +1,266 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pipelineDependencies from '@shopgate/pwa-core/classes/PipelineDependencies';
|
|
2
|
+
import appConfig from '@shopgate/pwa-common/helpers/config';
|
|
3
|
+
import showModal from '@shopgate/pwa-common/actions/modal/showModal';
|
|
4
|
+
import { appDidStart$ } from '@shopgate/pwa-common/streams';
|
|
5
|
+
import groupBy from 'lodash/groupBy';
|
|
6
|
+
import ToastProvider from '@shopgate/pwa-common/providers/toast';
|
|
7
|
+
import { makeGetRoutePattern } from '@shopgate/engage/core/selectors';
|
|
8
|
+
import { getLoadWishlistOnAppStartEnabled, getWishlistItemQuantityEnabled } from '@shopgate/engage/core/selectors/shopSettings';
|
|
9
|
+
import { LoadingProvider } from '@shopgate/pwa-common/providers';
|
|
10
|
+
import { favoritesWillEnter$, shouldFetchFreshFavorites$, addProductToFavoritesDebounced$, addProductToFavorites$, removeProductFromFavoritesDebounced$, errorFavoritesLimit$, refreshFavorites$, didReceiveFlushFavoritesBuffer$, updateProductInFavoritesDebounced$, favoritesDidAddItem$, favoritesSyncIdle$ } from "../streams";
|
|
11
|
+
import { SHOPGATE_USER_ADD_FAVORITES, SHOPGATE_USER_DELETE_FAVORITES } from "../constants/Pipelines";
|
|
12
|
+
import addFavorites from "../actions/addFavorites";
|
|
13
|
+
import updateFavorites from "../actions/updateFavorites";
|
|
14
|
+
import removeFavorites from "../actions/removeFavorites";
|
|
15
|
+
import fetchFavoritesListsWithItems from "../actions/fetchFavoritesListsWithItems";
|
|
16
|
+
import fetchFavorites from "../actions/fetchFavorites";
|
|
17
|
+
import { requestAddFavorites, requestRemoveFavorites, cancelRequestSyncFavorites, errorFavorites, idleSyncFavorites, requestUpdateFavorites } from "../action-creators";
|
|
18
|
+
import { REQUEST_ADD_FAVORITES, REQUEST_REMOVE_FAVORITES, FAVORITES_LIMIT_ERROR, REQUEST_UPDATE_FAVORITES, FAVORITES_PATH } from "../constants";
|
|
19
|
+
import { getFavoritesCount, makeGetFavoritesCountByList, makeGetProductRelativesOnFavorites, getFavoritesProducts, getUseGetFavoriteIdsPipeline } from "../selectors";
|
|
20
|
+
import fetchFavoriteIds from "../actions/fetchFavoriteIds";
|
|
21
|
+
|
|
22
|
+
/**
|
|
2
23
|
* @param {Function} subscribe Subscribes to an observable.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
24
|
+
*/
|
|
25
|
+
export default function favorites(subscribe) {
|
|
26
|
+
if (!appConfig.hasFavorites) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** App start */
|
|
31
|
+
subscribe(appDidStart$, async ({
|
|
32
|
+
dispatch,
|
|
33
|
+
getState
|
|
34
|
+
}) => {
|
|
35
|
+
// Setup sync pipeline dependencies (concurrency to each other and themselves)
|
|
36
|
+
pipelineDependencies.set(SHOPGATE_USER_ADD_FAVORITES, [SHOPGATE_USER_ADD_FAVORITES, SHOPGATE_USER_DELETE_FAVORITES]);
|
|
37
|
+
pipelineDependencies.set(SHOPGATE_USER_DELETE_FAVORITES, [SHOPGATE_USER_ADD_FAVORITES, SHOPGATE_USER_DELETE_FAVORITES]);
|
|
38
|
+
const loadWishlistOnAppStartEnabled = getLoadWishlistOnAppStartEnabled(getState());
|
|
39
|
+
if (loadWishlistOnAppStartEnabled && makeGetRoutePattern()(getState()) !== FAVORITES_PATH) {
|
|
40
|
+
await dispatch(fetchFavoritesListsWithItems(false));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/** Favorites route enter */
|
|
45
|
+
subscribe(favoritesWillEnter$, async ({
|
|
46
|
+
dispatch
|
|
47
|
+
}) => {
|
|
48
|
+
await dispatch(fetchFavoritesListsWithItems(true));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/** User login / logout */
|
|
52
|
+
subscribe(shouldFetchFreshFavorites$, async ({
|
|
53
|
+
dispatch
|
|
54
|
+
}) => {
|
|
55
|
+
await dispatch(fetchFavoritesListsWithItems(true));
|
|
56
|
+
});
|
|
57
|
+
subscribe(addProductToFavoritesDebounced$, ({
|
|
58
|
+
action,
|
|
59
|
+
dispatch,
|
|
60
|
+
getState
|
|
61
|
+
}) => {
|
|
62
|
+
const state = getState();
|
|
63
|
+
const wishlistItemQuantityEnabled = getWishlistItemQuantityEnabled(state);
|
|
64
|
+
|
|
65
|
+
// Nothing to do, when the store already contains the item
|
|
66
|
+
const activeProductInList = getFavoritesProducts(state).byList[action.listId]?.items.find(({
|
|
67
|
+
productId
|
|
68
|
+
}) => productId === action.productId);
|
|
69
|
+
if (activeProductInList && !wishlistItemQuantityEnabled) {
|
|
70
|
+
// Call cancel action with "zero" count, because request was even dispatched
|
|
71
|
+
dispatch(cancelRequestSyncFavorites(0, action.listId));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const {
|
|
75
|
+
favorites: {
|
|
76
|
+
limit = 100
|
|
77
|
+
} = {}
|
|
78
|
+
} = appConfig;
|
|
79
|
+
const count = makeGetFavoritesCountByList(() => action?.listId)(state);
|
|
80
|
+
// When the getFavorites pipeline is used to fetch favorites, the amount of items is limited
|
|
81
|
+
// since it returns full product entities. Hence adding more items needs to be prevented.
|
|
82
|
+
if (limit && count >= limit && !getUseGetFavoriteIdsPipeline(state)) {
|
|
83
|
+
// Dispatch a local error only, because the request to add is prevented
|
|
84
|
+
const error = new Error('Limit exceeded');
|
|
85
|
+
error.code = FAVORITES_LIMIT_ERROR;
|
|
86
|
+
dispatch(errorFavorites(action.productId, error));
|
|
87
|
+
} else {
|
|
88
|
+
dispatch(requestAddFavorites(action.productId, action.listId, action.quantity, action.notes, action.showToast));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
subscribe(updateProductInFavoritesDebounced$, ({
|
|
92
|
+
action,
|
|
93
|
+
dispatch
|
|
94
|
+
}) => {
|
|
95
|
+
dispatch(requestUpdateFavorites(action.productId, action.listId, action.quantity, action.notes));
|
|
96
|
+
});
|
|
97
|
+
subscribe(removeProductFromFavoritesDebounced$, ({
|
|
98
|
+
action,
|
|
99
|
+
dispatch,
|
|
100
|
+
getState
|
|
101
|
+
}) => {
|
|
102
|
+
const count = getFavoritesCount(getState());
|
|
103
|
+
if (count > 0) {
|
|
104
|
+
if (action.withRelatives) {
|
|
105
|
+
// Will only handle ids which are present in the store, no additional check needed
|
|
106
|
+
const allOnList = makeGetProductRelativesOnFavorites(() => action.listId)(getState(), {
|
|
107
|
+
productId: action.productId
|
|
108
|
+
});
|
|
109
|
+
allOnList.forEach(id => dispatch(requestRemoveFavorites(id, action.listId)));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Avoids trying to remove something that was already removed (incoming fetch response)
|
|
114
|
+
const list = getFavoritesProducts(getState()).byList[action.listId];
|
|
115
|
+
if (!list?.items.find(({
|
|
116
|
+
productId
|
|
117
|
+
}) => productId === action.productId)) {
|
|
118
|
+
// Call cancel action with "zero" count, because request was even dispatched
|
|
119
|
+
dispatch(cancelRequestSyncFavorites(0, action.listId));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
dispatch(requestRemoveFavorites(action.productId, action.listId));
|
|
123
|
+
} else if (!getFavoritesProducts(getState()).byList[action.listId]?.isFetching) {
|
|
124
|
+
// Remove should not be possible when no favorites available
|
|
125
|
+
// Refresh to fix inconsistencies, by dispatching an idleSync action when not fetching
|
|
126
|
+
dispatch(idleSyncFavorites(action.listId));
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Catch local limit errors (backend errors are handled autonomously)
|
|
131
|
+
subscribe(errorFavoritesLimit$, ({
|
|
132
|
+
dispatch
|
|
133
|
+
}) => {
|
|
134
|
+
dispatch(showModal({
|
|
135
|
+
confirm: null,
|
|
136
|
+
dismiss: 'modal.ok',
|
|
137
|
+
title: 'modal.title_error',
|
|
138
|
+
message: 'favorites.error_limit'
|
|
139
|
+
}));
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
/**
|
|
16
143
|
* Request after N seconds since last add or remove request to make sure
|
|
17
144
|
* backend did actually save it
|
|
18
|
-
*/
|
|
145
|
+
*/
|
|
146
|
+
subscribe(refreshFavorites$, async ({
|
|
147
|
+
dispatch,
|
|
148
|
+
action,
|
|
149
|
+
getState
|
|
150
|
+
}) => {
|
|
151
|
+
if (action.listId) {
|
|
152
|
+
const useGetFavoriteIdsPipeline = getUseGetFavoriteIdsPipeline(getState());
|
|
153
|
+
if (useGetFavoriteIdsPipeline) {
|
|
154
|
+
dispatch(fetchFavoriteIds(true, action.listId));
|
|
155
|
+
} else {
|
|
156
|
+
dispatch(fetchFavorites(true, action.listId));
|
|
157
|
+
}
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
await dispatch(fetchFavoritesListsWithItems(true));
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
/**
|
|
19
164
|
* Takes an action buffer of the request-add, request-remove and request-update favorites actions
|
|
20
165
|
* and triggers Pipeline requests for all of them. Errors are handled autonomously.
|
|
21
166
|
* After all pipeline requests are done it resets the favorite page's state to "idle".
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
167
|
+
*/
|
|
168
|
+
subscribe(didReceiveFlushFavoritesBuffer$, async actionBuffer => {
|
|
169
|
+
// This subscription handles bulk actions only
|
|
170
|
+
if (!Array.isArray(actionBuffer) || !actionBuffer.length) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
LoadingProvider.setLoading(FAVORITES_PATH);
|
|
174
|
+
|
|
175
|
+
// All actions provide the same functionality, just take the first entry
|
|
176
|
+
const {
|
|
177
|
+
dispatch
|
|
178
|
+
} = actionBuffer[0];
|
|
179
|
+
|
|
180
|
+
// Group all buffered actions by listId and productID
|
|
181
|
+
const actions = actionBuffer.map(({
|
|
182
|
+
action
|
|
183
|
+
}) => action);
|
|
184
|
+
const actionsByListAndProduct = groupBy(actions, ({
|
|
185
|
+
listId,
|
|
186
|
+
productId
|
|
187
|
+
}) => `${listId}-${productId}}`);
|
|
188
|
+
const idleLists = [];
|
|
189
|
+
await Object.values(actionsByListAndProduct).forEach(async groupedActions => {
|
|
190
|
+
const [{
|
|
191
|
+
productId,
|
|
192
|
+
listId,
|
|
193
|
+
quantity,
|
|
194
|
+
notes,
|
|
195
|
+
showToast
|
|
196
|
+
} = {}] = groupedActions;
|
|
197
|
+
const updateActions = groupedActions.filter(action => action.type === REQUEST_UPDATE_FAVORITES);
|
|
198
|
+
const addActions = groupedActions.filter(action => action.type === REQUEST_ADD_FAVORITES);
|
|
199
|
+
const removeActions = groupedActions.filter(action => action.type === REQUEST_REMOVE_FAVORITES);
|
|
200
|
+
try {
|
|
201
|
+
// If there are any update actions we only dispatch the last one
|
|
202
|
+
if (updateActions.length > 0) {
|
|
203
|
+
const [lastUpdateAction] = updateActions.slice(-1);
|
|
204
|
+
await dispatch(updateFavorites(lastUpdateAction.productId, lastUpdateAction.listId, lastUpdateAction.quantity, lastUpdateAction.notes));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Sum up all adds and removes, based on sum dispatch add / remove
|
|
208
|
+
const addRemoveBalance = addActions.length - removeActions.length;
|
|
209
|
+
if (addRemoveBalance > 0) {
|
|
210
|
+
await dispatch(addFavorites(productId, listId, quantity, notes, showToast));
|
|
211
|
+
}
|
|
212
|
+
if (addRemoveBalance < 0) {
|
|
213
|
+
await dispatch(removeFavorites(productId, listId, quantity, notes));
|
|
214
|
+
}
|
|
215
|
+
if (updateActions.length === 0 && addRemoveBalance === 0) {
|
|
216
|
+
dispatch(cancelRequestSyncFavorites(groupedActions.length, listId));
|
|
217
|
+
} else if (!idleLists.includes(listId)) {
|
|
218
|
+
idleLists.push(listId);
|
|
219
|
+
await dispatch(idleSyncFavorites(listId));
|
|
220
|
+
}
|
|
221
|
+
} catch (error) {
|
|
222
|
+
if (!idleLists.includes(listId)) {
|
|
223
|
+
idleLists.push(listId);
|
|
224
|
+
await dispatch(idleSyncFavorites(listId));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
subscribe(favoritesSyncIdle$, () => {
|
|
230
|
+
LoadingProvider.resetLoading(FAVORITES_PATH);
|
|
231
|
+
});
|
|
232
|
+
subscribe(addProductToFavorites$, ({
|
|
233
|
+
events,
|
|
234
|
+
getState,
|
|
235
|
+
action
|
|
236
|
+
}) => {
|
|
237
|
+
const loadWishlistOnAppStartEnabled = getLoadWishlistOnAppStartEnabled(getState());
|
|
238
|
+
|
|
239
|
+
// When wish list loading on app start is disabled, toast is shown instantly after the add
|
|
240
|
+
// action was dispatched. We don't have to wait for the "debounced" action, since
|
|
241
|
+
// removal of wishlist items is not possible.
|
|
242
|
+
if (!loadWishlistOnAppStartEnabled && action?.showToast !== false) {
|
|
243
|
+
events.emit(ToastProvider.ADD, {
|
|
244
|
+
id: 'favorites.added',
|
|
245
|
+
message: 'favorites.added'
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
subscribe(favoritesDidAddItem$, ({
|
|
250
|
+
events,
|
|
251
|
+
getState,
|
|
252
|
+
action
|
|
253
|
+
}) => {
|
|
254
|
+
const loadWishlistOnAppStartEnabled = getLoadWishlistOnAppStartEnabled(getState());
|
|
255
|
+
|
|
256
|
+
// When wish list loading on app start is enabled, toast is shown after the add action from
|
|
257
|
+
// the buffer system is dispatched. We wait for that since the item might have been removed
|
|
258
|
+
// again within the debounce time.
|
|
259
|
+
if (loadWishlistOnAppStartEnabled && action?.showToast !== false) {
|
|
260
|
+
events.emit(ToastProvider.ADD, {
|
|
261
|
+
id: 'favorites.added',
|
|
262
|
+
message: 'favorites.added'
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|