Created
March 4, 2020 12:35
-
-
Save senadir/4e00f6db5b1a1f6ad398fce555099399 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
--- a/assets/js/blocks/cart-checkout/cart/full-cart/cart-line-item-row.js | |
+++ b/assets/js/blocks/cart-checkout/cart/full-cart/cart-line-item-row.js | |
@@ -1,7 +1,7 @@ | |
/** | |
* External dependencies | |
*/ | |
-import { RawHTML } from '@wordpress/element'; | |
+import { RawHTML, useState, useEffect } from '@wordpress/element'; | |
import { __, sprintf } from '@wordpress/i18n'; | |
import PropTypes from 'prop-types'; | |
import QuantitySelector from '@woocommerce/base-components/quantity-selector'; | |
@@ -9,7 +9,7 @@ import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-mone | |
import { getCurrency, formatPrice } from '@woocommerce/base-utils'; | |
import { useStoreCartItem } from '@woocommerce/base-hooks'; | |
import { Icon, trash } from '@woocommerce/icons'; | |
- | |
+import { useDebounce } from 'use-debounce'; | |
/** | |
* Internal dependencies | |
*/ | |
@@ -40,9 +40,12 @@ const CartLineItemRow = ( { lineItem = {} } ) => { | |
const { | |
changeQuantity, | |
removeItem, | |
- isPending: itemQuantityDisabled, | |
} = useStoreCartItem( key ); | |
- | |
+ const [localQuantity, setQuantity] = useState(quantity); | |
+ const [debouncedQuantity] = useDebounce(localQuantity, 400); | |
+ useEffect(() => { | |
+ changeQuantity( debouncedQuantity ) | |
+ }, [ debouncedQuantity ] ) | |
return ( | |
<tr className="wc-block-cart-items__row"> | |
<td className="wc-block-cart-item__image"> | |
@@ -67,21 +70,20 @@ const CartLineItemRow = ( { lineItem = {} } ) => { | |
</td> | |
<td className="wc-block-cart-item__quantity"> | |
<QuantitySelector | |
- disabled={ itemQuantityDisabled } | |
- quantity={ quantity } | |
+ }, [ debouncedQuantity ] ) | |
return ( | |
<tr className="wc-block-cart-items__row"> | |
<td className="wc-block-cart-item__image"> | |
@@ -67,21 +70,20 @@ const CartLineItemRow = ( { lineItem = {} } ) => { | |
</td> | |
<td className="wc-block-cart-item__quantity"> | |
<QuantitySelector | |
- disabled={ itemQuantityDisabled } | |
- quantity={ quantity } | |
+ quantity={ localQuantity } | |
maximum={ lineItem.sold_individually ? 1 : undefined } | |
- onChange={ changeQuantity } | |
+ onChange={ (val) => { | |
+ setQuantity(val); | |
+ } } | |
itemName={ name } | |
/> | |
<button | |
- disabled={ itemQuantityDisabled } | |
className="wc-block-cart-item__remove-link" | |
onClick={ removeItem } | |
> | |
{ __( 'Remove item', 'woo-gutenberg-products-block' ) } | |
</button> | |
<button | |
- disabled={ itemQuantityDisabled } | |
className="wc-block-cart-item__remove-icon" | |
onClick={ removeItem } | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment