From f9d8cee4f6faffc892317c24eaadfa0ac947a735 Mon Sep 17 00:00:00 2001 From: Reza_ashrafi Date: Thu, 14 Apr 2022 00:28:45 +0430 Subject: [PATCH] reza fixed loagin in cart --- src/redux/proxy.js | 1 - .../ShoppingCart/components/Product.js | 67 ++++++++++++------- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/redux/proxy.js b/src/redux/proxy.js index afcf307..741325d 100644 --- a/src/redux/proxy.js +++ b/src/redux/proxy.js @@ -69,7 +69,6 @@ class Proxy { } break; case 403: - console.log(url.split("/")[0] + "/" + "error"), dispatch({ type: url.split("/")[0] + "/" + "error", // data: response.data, diff --git a/src/screens/ShoppingCart/components/Product.js b/src/screens/ShoppingCart/components/Product.js index 88b2f07..e919df9 100644 --- a/src/screens/ShoppingCart/components/Product.js +++ b/src/screens/ShoppingCart/components/Product.js @@ -22,6 +22,19 @@ const width = Dimensions.get("window").width; const ios = Platform.OS === "ios"; function Product({ product, grades, pushToCart, loading, mobile, theme }) { + const [selectedProduct, setSelectedProduct] = React.useState(null); + + const submit = async (action) => { + setSelectedProduct(product?.productId); + await action(); + }; + + React.useEffect(() => { + if(!loading){ + setSelectedProduct(null); + } + },[loading]); + return ( - {separate(product?.product?.price) || ' '} + {separate(product?.product?.price) || " "} @@ -118,14 +131,16 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { size={mobile ? 20 : 30} color={Colors.theme1[theme].redFF1} onPress={() => - pushToCart( - { - productId: product?.productId, - userId: product?.userId, - count: product?.productType === 1 ? -1 : -product?.count, - }, - {}, - { id: product?.factorId } + submit( + pushToCart( + { + productId: product?.productId, + userId: product?.userId, + count: product?.productType === 1 ? -1 : -product?.count, + }, + {}, + { id: product?.factorId } + ) ) } /> @@ -137,11 +152,13 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { > - pushToCart({ - productId: product?.productId, - userId: product?.userId, - count: 1, - }) + submit( + pushToCart({ + productId: product?.productId, + userId: product?.userId, + count: 1, + }) + ) } style={[ tw( @@ -164,13 +181,13 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { + - {/* {loading ? ( + {loading && selectedProduct === product?.productId ? ( - ) : ( */} + ) : ( {product?.count} - {/* )} */} + )} - pushToCart({ - productId: product?.productId, - userId: product?.userId, - count: -1, - }) + submit( + pushToCart({ + productId: product?.productId, + userId: product?.userId, + count: -1, + }) + ) } style={[ tw( @@ -233,7 +252,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { }, ]} > - {separate(product?.product?.price * product?.count) || ' '} + {separate(product?.product?.price * product?.count) || " "} @@ -245,7 +264,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) { const mapStateToProps = (state) => ({ grades: state.publicApi.grades, mobile: state.publicApi.mobile, - theme: state.publicApi.theme + theme: state.publicApi.theme, }); const mapDispatchToProps = {