reza fixed loagin in cart

master
Reza_ashrafi 3 years ago
parent 314bd19066
commit f9d8cee4f6
  1. 1
      src/redux/proxy.js
  2. 31
      src/screens/ShoppingCart/components/Product.js

@ -69,7 +69,6 @@ class Proxy {
} }
break; break;
case 403: case 403:
console.log(url.split("/")[0] + "/" + "error"),
dispatch({ dispatch({
type: url.split("/")[0] + "/" + "error", type: url.split("/")[0] + "/" + "error",
// data: response.data, // data: response.data,

@ -22,6 +22,19 @@ const width = Dimensions.get("window").width;
const ios = Platform.OS === "ios"; const ios = Platform.OS === "ios";
function Product({ product, grades, pushToCart, loading, mobile, theme }) { 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 ( return (
<View <View
style={[ style={[
@ -105,7 +118,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
}, },
]} ]}
> >
{separate(product?.product?.price) || ' '} {separate(product?.product?.price) || " "}
</Text> </Text>
</View> </View>
</View> </View>
@ -118,6 +131,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
size={mobile ? 20 : 30} size={mobile ? 20 : 30}
color={Colors.theme1[theme].redFF1} color={Colors.theme1[theme].redFF1}
onPress={() => onPress={() =>
submit(
pushToCart( pushToCart(
{ {
productId: product?.productId, productId: product?.productId,
@ -127,6 +141,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
{}, {},
{ id: product?.factorId } { id: product?.factorId }
) )
)
} }
/> />
<View style={tw("flex items-center mt-2")}> <View style={tw("flex items-center mt-2")}>
@ -137,11 +152,13 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
> >
<Pressable <Pressable
onPress={() => onPress={() =>
submit(
pushToCart({ pushToCart({
productId: product?.productId, productId: product?.productId,
userId: product?.userId, userId: product?.userId,
count: 1, count: 1,
}) })
)
} }
style={[ style={[
tw( tw(
@ -164,13 +181,13 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
+ +
</Text> </Text>
</Pressable> </Pressable>
{/* {loading ? ( {loading && selectedProduct === product?.productId ? (
<ActivityIndicator <ActivityIndicator
style={tw("mx-2")} style={tw("mx-2")}
size="small" size="small"
color={Colors.theme1[theme].greenBA} color={Colors.theme1[theme].greenBA}
/> />
) : ( */} ) : (
<Text <Text
style={[ style={[
tw("mx-2.5"), tw("mx-2.5"),
@ -183,15 +200,17 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
> >
{product?.count} {product?.count}
</Text> </Text>
{/* )} */} )}
<Pressable <Pressable
onPress={() => onPress={() =>
submit(
pushToCart({ pushToCart({
productId: product?.productId, productId: product?.productId,
userId: product?.userId, userId: product?.userId,
count: -1, count: -1,
}) })
)
} }
style={[ style={[
tw( 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) || " "}
</Text> </Text>
</View> </View>
</View> </View>
@ -245,7 +264,7 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
grades: state.publicApi.grades, grades: state.publicApi.grades,
mobile: state.publicApi.mobile, mobile: state.publicApi.mobile,
theme: state.publicApi.theme theme: state.publicApi.theme,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {

Loading…
Cancel
Save