diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart-item-quantity.ts b/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart-item-quantity.ts index 0ab68da5c3f..5a0d306ed94 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart-item-quantity.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart-item-quantity.ts @@ -6,7 +6,6 @@ import { useCallback, useState, useEffect } from '@wordpress/element'; import { CART_STORE_KEY, CHECKOUT_STORE_KEY } from '@woocommerce/block-data'; import { useDebounce } from 'use-debounce'; import { usePrevious } from '@woocommerce/base-hooks'; -import { triggerFragmentRefresh } from '@woocommerce/base-utils'; import { CartItem, StoreCartItemQuantity, @@ -86,10 +85,7 @@ export const useStoreCartItemQuantity = ( const removeItem = useCallback( () => { return cartItemKey - ? removeItemFromCart( cartItemKey ).then( () => { - triggerFragmentRefresh(); - return true; - } ) + ? removeItemFromCart( cartItemKey ) : Promise.resolve( false ); }, [ cartItemKey, removeItemFromCart ] ); diff --git a/plugins/woocommerce-blocks/assets/js/base/utils/legacy-events.ts b/plugins/woocommerce-blocks/assets/js/base/utils/legacy-events.ts index 8fcaad476ed..18936876d44 100644 --- a/plugins/woocommerce-blocks/assets/js/base/utils/legacy-events.ts +++ b/plugins/woocommerce-blocks/assets/js/base/utils/legacy-events.ts @@ -42,23 +42,6 @@ export const dispatchEvent = ( element.dispatchEvent( event ); }; -let fragmentRequestTimeoutId: ReturnType< typeof setTimeout >; - -// This is a hack to trigger cart updates till we migrate to block based cart -// that relies on the store, see -// https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/1247 -export const triggerFragmentRefresh = (): void => { - if ( fragmentRequestTimeoutId ) { - clearTimeout( fragmentRequestTimeoutId ); - } - fragmentRequestTimeoutId = setTimeout( () => { - dispatchEvent( 'wc_fragment_refresh', { - bubbles: true, - cancelable: true, - } ); - }, 50 ); -}; - export const triggerAddingToCartEvent = (): void => { dispatchEvent( 'wc-blocks_adding_to_cart', { bubbles: true, diff --git a/plugins/woocommerce-blocks/assets/js/data/cart/action-types.ts b/plugins/woocommerce-blocks/assets/js/data/cart/action-types.ts index 0f1288fdeba..2a8796ca92b 100644 --- a/plugins/woocommerce-blocks/assets/js/data/cart/action-types.ts +++ b/plugins/woocommerce-blocks/assets/js/data/cart/action-types.ts @@ -12,7 +12,6 @@ export const ACTION_TYPES = { SET_BILLING_ADDRESS: 'SET_BILLING_ADDRESS', SET_SHIPPING_ADDRESS: 'SET_SHIPPING_ADDRESS', UPDATING_SELECTED_SHIPPING_RATE: 'UPDATING_SELECTED_SHIPPING_RATE', - UPDATE_LEGACY_CART_FRAGMENTS: 'UPDATE_LEGACY_CART_FRAGMENTS', TRIGGER_ADDING_TO_CART_EVENT: 'TRIGGER_ADDING_TO_CART_EVENT', TRIGGER_ADDED_TO_CART_EVENT: 'TRIGGER_ADDED_TO_CART_EVENT', } as const; diff --git a/plugins/woocommerce-blocks/assets/js/data/cart/actions.ts b/plugins/woocommerce-blocks/assets/js/data/cart/actions.ts index 2b5afb94816..8a1fdb037ce 100644 --- a/plugins/woocommerce-blocks/assets/js/data/cart/actions.ts +++ b/plugins/woocommerce-blocks/assets/js/data/cart/actions.ts @@ -184,14 +184,6 @@ export const shippingRatesBeingSelected = ( isResolving: boolean ) => isResolving, } as const ); -/** - * Returns an action object for updating legacy cart fragments. - */ -export const updateCartFragments = () => - ( { - type: types.UPDATE_LEGACY_CART_FRAGMENTS, - } as const ); - /** * Triggers an adding to cart event so other blocks can update accordingly. */ @@ -227,7 +219,6 @@ export function* applyExtensionCartUpdate( cache: 'no-store', } ); yield receiveCart( response ); - yield updateCartFragments(); return response; } catch ( error ) { yield receiveError( error ); @@ -265,7 +256,6 @@ export function* applyCoupon( yield receiveCart( response ); yield receiveApplyingCoupon( '' ); - yield updateCartFragments(); } catch ( error ) { yield receiveError( error ); yield receiveApplyingCoupon( '' ); @@ -306,7 +296,6 @@ export function* removeCoupon( yield receiveCart( response ); yield receiveRemovingCoupon( '' ); - yield updateCartFragments(); } catch ( error ) { yield receiveError( error ); yield receiveRemovingCoupon( '' ); @@ -351,7 +340,6 @@ export function* addItemToCart( yield receiveCart( response ); yield triggerAddedToCartEvent( { preserveCartData: true } ); - yield updateCartFragments(); } catch ( error ) { yield receiveError( error ); @@ -390,7 +378,6 @@ export function* removeItemFromCart( } ); yield receiveCart( response ); - yield updateCartFragments(); } catch ( error ) { yield receiveError( error ); @@ -437,7 +424,6 @@ export function* changeCartItemQuantity( } ); yield receiveCart( response ); - yield updateCartFragments(); } catch ( error ) { yield receiveError( error ); @@ -559,5 +545,4 @@ export type CartAction = ReturnOrGeneratorYieldUnion< | typeof removeItemFromCart | typeof changeCartItemQuantity | typeof addItemToCart - | typeof updateCartFragments >; diff --git a/plugins/woocommerce-blocks/assets/js/data/cart/controls.js b/plugins/woocommerce-blocks/assets/js/data/cart/controls.js index de3dfc34cda..22eaac09f01 100644 --- a/plugins/woocommerce-blocks/assets/js/data/cart/controls.js +++ b/plugins/woocommerce-blocks/assets/js/data/cart/controls.js @@ -2,7 +2,6 @@ * External dependencies */ import { - triggerFragmentRefresh, triggerAddedToCartEvent, triggerAddingToCartEvent, } from '@woocommerce/base-utils'; @@ -13,9 +12,6 @@ import { * @return {Object} An object with the controls to register with the store on the controls property of the registration object. */ export const controls = { - UPDATE_LEGACY_CART_FRAGMENTS() { - triggerFragmentRefresh(); - }, TRIGGER_ADDING_TO_CART_EVENT() { triggerAddingToCartEvent(); }, diff --git a/plugins/woocommerce-blocks/checkstyle.xml b/plugins/woocommerce-blocks/checkstyle.xml index 997e4543c83..3f21920e631 100644 --- a/plugins/woocommerce-blocks/checkstyle.xml +++ b/plugins/woocommerce-blocks/checkstyle.xml @@ -497,30 +497,30 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -633,7 +633,7 @@ - + @@ -834,6 +834,12 @@ + + + + Type 'Promise<void>' is not assignable to type 'Promise<boolean>'." source="TS2322" />