import React, { useState, useEffect } from "react"; import { View, Text, Image, ScrollView, TouchableHighlight, Dimensions, Appearance, Pressable, Platform, ActivityIndicator, } from "react-native"; import { useNavigation } from "@react-navigation/native"; import { product, userProduct } from "../../../redux/actions"; import { connect } from "react-redux"; import { Entypo } from "@expo/vector-icons"; import separate from "../../../utils/separate"; //components import CustomPressable from "../../../components/Pressable"; import Description from "./Description"; import LinkBox from "./LinkBox"; import Comments from "./Comments"; import ProductSpecifications from "../../../components/BottomSheetComponents/ProductSpecifications"; import ProductReview from "../../../components/BottomSheetComponents/ProductReview"; import ProductQuestion from "../../../components/BottomSheetComponents/ProductQuestion"; import Blur from "../../../components/Blur"; import ImageSlider from "../../../components/ImageSlider"; //style import tw from "tailwind-rn"; import fontSize from "../../../constants/fontSize"; import Colors from "../../../constants/Colors"; const { height, width } = Dimensions.get("window"); const ios = Platform.OS === "ios"; function Book({ book, grades, pushToCart, userId, loading, mobile, userProducts, }) { const colorScheme = Appearance.getColorScheme(); const navigation = useNavigation(); const [type, setType] = useState(1); const [pageLoading, setPageLoading] = useState(false); const [imageSlider, setImageSlider] = useState(false); useEffect(() => { setPageLoading(true); setTimeout(() => { setPageLoading(false); }, 500); }, [type]); const physicalAvailabileInCart = userProducts?.filter( (product) => product?.productId === book?.product[1]?.id )[0]; const digitalAvailabileInCart = userProducts?.filter( (product) => product?.productId === book?.product[0]?.id )[0]; return ( {!mobile && } {pageLoading && ( )} {imageSlider && } {book?.name} {"پایه" + " " + grades[book?.gradeId]} {book?.text} {" "} {book?.pagesNum + "\n" + "صفحه"} {" "} {"فیزیکی- دیجیتالی - ویدئو" + "\n" + "در دسترس"} {" "} {4.8 + "\n" + "امتیاز"} نسخه محصول را انتخاب کنید pushToCart({ productId: book?.product[1]?.id, userId: userId, count: 1, }) } > <> خرید نسخه فیزیکی کتاب {separate(book?.product[1]?.price) + " " + "تومان"} {physicalAvailabileInCart && ( pushToCart({ productId: physicalAvailabileInCart?.productId, userId: physicalAvailabileInCart.userId, count: 1, }) } style={[ tw( `rounded-md py-0 flex flex-row justify-center items-center border ${ mobile ? "px-1.5" : "px-3" }` ), { borderColor: Colors.theme1[colorScheme].green79, }, ]} > + {loading ? ( ) : ( {physicalAvailabileInCart?.count} )} pushToCart({ productId: physicalAvailabileInCart?.productId, userId: physicalAvailabileInCart?.userId, count: -1, }) } style={[ tw( `rounded-md flex flex-row justify-center items-center border ${ mobile ? "px-2" : "px-3.5" }` ), { borderColor: Colors.theme1[colorScheme].green79, }, ]} > - )} pushToCart({ productId: book?.product[0]?.id, userId: userId, count: 1, }) } > <> خرید نسخه دیجیتال کتاب {separate(book?.product[0]?.price) + " " + "تومان"} {digitalAvailabileInCart && ( pushToCart({ productId: digitalAvailabileInCart?.productId, userId: digitalAvailabileInCart.userId, count: 1, }) } style={[ tw( `rounded-md py-0 flex flex-row justify-center items-center border ${ mobile ? "px-1.5" : "px-3" }` ), { borderColor: Colors.theme1[colorScheme].green79, }, ]} > + {loading ? ( ) : ( {digitalAvailabileInCart?.count} )} pushToCart({ productId: digitalAvailabileInCart?.productId, userId: digitalAvailabileInCart?.userId, count: -1, }) } style={[ tw( `rounded-md flex flex-row justify-center items-center border ${ mobile ? "px-2" : "px-3.5" }` ), { borderColor: Colors.theme1[colorScheme].green79, }, ]} > - )} navigation.push("Sample", { id: book?.sampleFileId })} > مشاهده نمونه pushToCart({ productId: book?.product[2]?.id, userId: userId, count: 1, }) } > <> خرید دوره ویدئویی کتاب {separate(book?.product[2]?.price) + " " + "تومان"} navigation.navigate("Video", { id: book?.id })} > پیش نمایش {book?.product[type]?.description && ( )} } height={height - height / 4} /> } height={height - height / 4} /> } height={height - height / 4} /> {product.rates && ( امتیازات و نظرات )} {/* */} ); } const mapStateToProps = (state) => ({ userProducts: state.userProduct.list, userId: state.user.status?.id, loading: state.userProduct.loading, mobile: state.publicApi.mobile, }); const mapDispatchToProps = { pushToCart: userProduct.add, }; export default connect(mapStateToProps, mapDispatchToProps)(Book);