reza fixed error before 18

master
Reza_ashrafi 3 years ago
parent f983c60bc9
commit 24b1dba5d4
  1. 3
      navigation/index.js
  2. 15
      src/components/AlertModal.js
  3. 1
      src/components/Drawer.js
  4. 7
      src/components/Navbar.js
  5. 1
      src/redux/actions/userProduct.js
  6. 1
      src/redux/reducers/userFactor.js
  7. 1
      src/redux/reducers/userProduct.js
  8. 10
      src/screens/Home/components/Blogs.js
  9. 2
      src/screens/Home/index.js
  10. 12
      src/screens/Otp/index.js
  11. 115
      src/screens/Product/components/Book.js
  12. 2
      src/screens/Profile/components/User.js
  13. 46
      src/screens/ShoppingCart/components/Code.js
  14. 403
      src/screens/ShoppingCart/components/Product.js
  15. 8
      src/screens/ShoppingCart/index.js
  16. 65
      src/screens/Video/index.js
  17. 17
      src/screens/VideoDisplay/index.js

@ -352,6 +352,7 @@ const HomeStackScreen = () => {
<HomeStack.Screen name="Home" component={Home} /> <HomeStack.Screen name="Home" component={Home} />
<HomeStack.Screen name="VOD" component={Videos} /> <HomeStack.Screen name="VOD" component={Videos} />
<HomeStack.Screen name="Video" component={Video} unmountOnExit={true} /> <HomeStack.Screen name="Video" component={Video} unmountOnExit={true} />
<HomeStack.Screen name="ShoppingCart" component={ShoppingCart} />
<HomeStack.Screen name="VideoDisplay" component={VideoDisplay} /> <HomeStack.Screen name="VideoDisplay" component={VideoDisplay} />
<HomeStack.Screen name="Products" component={Products} /> <HomeStack.Screen name="Products" component={Products} />
<HomeStack.Screen name="Product" component={Product} /> <HomeStack.Screen name="Product" component={Product} />
@ -375,6 +376,7 @@ const ProductsStackScreen = () => {
> >
<ProductsStack.Screen name="Products" component={Products} /> <ProductsStack.Screen name="Products" component={Products} />
<ProductsStack.Screen name="Product" component={Product} /> <ProductsStack.Screen name="Product" component={Product} />
<ProductsStack.Screen name="ShoppingCart" component={ShoppingCart} />
<ProductsStack.Screen name="Sample" component={Sample} /> <ProductsStack.Screen name="Sample" component={Sample} />
<ProductsStack.Screen name="Info" component={Info} /> <ProductsStack.Screen name="Info" component={Info} />
</ProductsStack.Navigator> </ProductsStack.Navigator>
@ -392,6 +394,7 @@ const VODStackScreen = () => {
> >
<VODStack.Screen name="VOD" component={Videos} /> <VODStack.Screen name="VOD" component={Videos} />
<VODStack.Screen name="Video" component={Video} unmountOnExit={true} /> <VODStack.Screen name="Video" component={Video} unmountOnExit={true} />
<VODStack.Screen name="ShoppingCart" component={ShoppingCart} />
<VODStack.Screen name="VideoDisplay" component={VideoDisplay} /> <VODStack.Screen name="VideoDisplay" component={VideoDisplay} />
</VODStack.Navigator> </VODStack.Navigator>
); );

@ -91,18 +91,31 @@ const AlertModal = props => {
confirmButtonColor={alert.confirmButtonColor} confirmButtonColor={alert.confirmButtonColor}
onCancelPressed={onCancelPressed} onCancelPressed={onCancelPressed}
onConfirmPressed={(onConfirmPressed)} onConfirmPressed={(onConfirmPressed)}
cancelButtonTextStyle={{
color : '#777',
fontFamily : 'regular',
}}
confirmButtonTextStyle={{
fontFamily : 'regular',
}}
contentStyle={{ contentStyle={{
width: ReactNative.Dimensions.get('window').width / 1.5, width: ReactNative.Dimensions.get('window').width / 1.5,
}} }}
cancelButtonStyle={{ cancelButtonStyle={{
fontFamily : 'regular', fontFamily : 'regular',
borderColor : "#777",
borderWidth : 1,
backgroundColor : 'white',
}} }}
confirmButtonStyle={ confirmButtonStyle={
{ {
width: ReactNative.Dimensions.get('window').width / 4, width: ReactNative.Dimensions.get('window').width / 4,
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
fontFamily : 'regular' fontFamily : 'regular',
borderColor : "#2980b9",
borderWidth : 1,
} }
} }
useNativeDriver={true} useNativeDriver={true}

@ -9,7 +9,6 @@ import {
TouchableOpacity, TouchableOpacity,
Image, Image,
LayoutAnimation, LayoutAnimation,
StatusBar,
} from "react-native"; } from "react-native";
import { useNavigation } from "@react-navigation/native"; import { useNavigation } from "@react-navigation/native";
import { asyncAwesomeAlert } from "../utils/AsyncWrappers"; import { asyncAwesomeAlert } from "../utils/AsyncWrappers";

@ -5,6 +5,7 @@ import {
Text, Text,
Appearance, Appearance,
TouchableOpacity, TouchableOpacity,
ActivityIndicator,
} from "react-native"; } from "react-native";
import Svg, { import Svg, {
@ -36,6 +37,7 @@ const Navbar = ({
deleteBookmark, deleteBookmark,
userFavoriteList, userFavoriteList,
theme, theme,
bookmarkLoading,
}) => { }) => {
const navigation = useNavigation(); const navigation = useNavigation();
@ -391,7 +393,9 @@ const Navbar = ({
</> </>
)} )}
{headerOptions?.bookmark && {headerOptions?.bookmark &&
(isActiveBookmark ? ( (bookmarkLoading ? (
<ActivityIndicator size={20} color={Color.theme1[theme].green79} />
) : isActiveBookmark ? (
<Ionicons <Ionicons
name="bookmark" name="bookmark"
style={tw("mr-2")} style={tw("mr-2")}
@ -443,6 +447,7 @@ const Navbar = ({
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
userFavoriteList: state.userFavorite.list, userFavoriteList: state.userFavorite.list,
theme: state.publicApi.theme, theme: state.publicApi.theme,
bookmarkLoading: state.userFavorite.loading,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {

@ -19,7 +19,6 @@ const userProduct = {
(data = {}, data2 = {}, data3 = {}) => (data = {}, data2 = {}, data3 = {}) =>
async (dispatch) => { async (dispatch) => {
await proxy.post("userProduct/add", data, { dispatch }); await proxy.post("userProduct/add", data, { dispatch });
await proxy.get("userProduct/list", data2, { dispatch });
await proxy.get("userFactor/info", data3, { dispatch }); await proxy.get("userFactor/info", data3, { dispatch });
}, },
del: del:

@ -58,6 +58,7 @@ export default function userFactor(state = initialState, action) {
case "userFactor/error": case "userFactor/error":
asyncAwesomeAlert("خطا", data.message, { asyncAwesomeAlert("خطا", data.message, {
showCancelButton: false, showCancelButton: false,
confirmText: "باشه"
}); });
return { ...state, loading: false, error: data.message }; return { ...state, loading: false, error: data.message };
default: default:

@ -23,6 +23,7 @@ export default function userFactor(state = initialState, action) {
data.filter((item) => item.product.productType === 2).length > 0 data.filter((item) => item.product.productType === 2).length > 0
? true ? true
: false; : false;
console.log('list fetched!');
return { return {
...state, ...state,
loading: false, loading: false,

@ -29,7 +29,7 @@ const ios = Platform.OS === "ios";
function Blogs({ blogs, mobile, theme }) { function Blogs({ blogs, mobile, theme }) {
return ( return (
<View style={[tw("flex mb-5")]}> <View style={[tw("flex")]}>
<View style={tw("w-full px-4")}> <View style={tw("w-full px-4")}>
<Header title={"خواندنیها"} route={"Blogs"} /> <Header title={"خواندنیها"} route={"Blogs"} />
</View> </View>
@ -37,8 +37,8 @@ function Blogs({ blogs, mobile, theme }) {
showsHorizontalScrollIndicator={false} showsHorizontalScrollIndicator={false}
horizontal={true} horizontal={true}
inverted={true} inverted={true}
style={[tw("flex flex-row mt-3 pb-7")]} style={[tw("flex flex-row mt-3")]}
data={blogs.slice(0,7)} data={blogs.slice(0, 7)}
renderItem={({ item }) => ( renderItem={({ item }) => (
<Blog blog={item} mobile={mobile} theme={theme} /> <Blog blog={item} mobile={mobile} theme={theme} />
)} )}
@ -51,11 +51,10 @@ function Blogs({ blogs, mobile, theme }) {
const Blog = ({ blog, mobile, theme }) => { const Blog = ({ blog, mobile, theme }) => {
const navigation = useNavigation(); const navigation = useNavigation();
return ( return (
<Pressable <Pressable
style={[ style={[
tw("rounded-md mr-4 rounded-md relative"), tw("mr-4 relative"),
{ width: mobile ? 250 : width / 2.2 }, { width: mobile ? 250 : width / 2.2 },
]} ]}
onPress={() => navigation.push("Blog", { id: blog?.id })} onPress={() => navigation.push("Blog", { id: blog?.id })}
@ -64,7 +63,6 @@ const Blog = ({ blog, mobile, theme }) => {
source={{ uri: `https://dnvn.ir/api/v1/file/${blog.fileIds}` }} source={{ uri: `https://dnvn.ir/api/v1/file/${blog.fileIds}` }}
resizeMode="contain" resizeMode="contain"
style={[ style={[
tw("rounded-md"),
{ {
flex: 1, flex: 1,
height: mobile ? 180 : ((width / 2.2) * 9) / 16, height: mobile ? 180 : ((width / 2.2) * 9) / 16,

@ -78,7 +78,7 @@ const Home = ({
// Later on in your styles.. // Later on in your styles..
const styles = StyleSheet.create({ const styles = StyleSheet.create({
contentContainerStyle: { contentContainerStyle: {
paddingBottom: 40, // paddingBottom: 40,
// flex : 1, // flex : 1,
// alignItems: "", // alignItems: "",
}, },

@ -118,7 +118,7 @@ function Otp(props) {
let timeout = setTimeout(() => { let timeout = setTimeout(() => {
clearInterval(interval); clearInterval(interval);
setTimeEnd(true); setTimeEnd(true);
}, 10000); }, 120000);
return () => { return () => {
clearInterval(interval); clearInterval(interval);
clearTimeout(timeout); clearTimeout(timeout);
@ -132,10 +132,14 @@ function Otp(props) {
const hour = Math.floor(value / 60); const hour = Math.floor(value / 60);
return ( return (
(hour > 0 (hour > 0
? (hour.toString().length === 1 ? "0" + hour.toString() : hour) + "" ? (minute.toString().length === 1
? "0" + minute.toString()
: minute) + ""
: "") + : "") +
" " +
":" + ":" +
(minute.toString().length === 1 ? "0" + minute.toString() : minute) " " +
(hour.toString().length === 1 ? "0" + hour.toString() : hour)
); );
}, },
[props.route] [props.route]
@ -345,7 +349,7 @@ function Otp(props) {
}, },
]} ]}
> >
{"زمان باقی مانده تا ارسال مجدد: " + duration(time)} {"زمان باقی مانده تا ارسال مجدد:" + " " + duration(time) + " "}
</Text> </Text>
) : ( ) : (
<View style={tw("flex")}> <View style={tw("flex")}>

@ -44,6 +44,7 @@ function Book({
}) { }) {
const navigation = useNavigation(); const navigation = useNavigation();
const [type, setType] = useState(1); const [type, setType] = useState(1);
const [whichTypeAdded, setWhichTypeAdded] = React.useState(null);
const [pageLoading, setPageLoading] = useState(false); const [pageLoading, setPageLoading] = useState(false);
const [imageSlider, setImageSlider] = useState(false); const [imageSlider, setImageSlider] = useState(false);
@ -66,10 +67,54 @@ function Book({
)[0]; )[0];
}, [userProducts, book]); }, [userProducts, book]);
const videoAvailabileInCart = React.useMemo(() => {
return userProducts?.filter(
(product) => product?.productId === book?.product[2]?.id
)[0];
}, [userProducts, book]);
const addToCart = React.useCallback(
async (action, type) => {
setWhichTypeAdded(type);
await action();
},
[book, userId]
);
React.useEffect(() => {
if (userProducts.length && whichTypeAdded) {
setTimeout(() => {
if (whichTypeAdded === "video" && videoAvailabileInCart) {
asyncAwesomeAlert("", "به سبد خرید اضافه شد", {
showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
});
} else if (whichTypeAdded === "physical" && physicalAvailabileInCart) {
asyncAwesomeAlert("", "به سبد خرید اضافه شد", {
showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
});
} else if (whichTypeAdded === "digital" && digitalAvailabileInCart) {
asyncAwesomeAlert("", "به سبد خرید اضافه شد", {
showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
});
}
setWhichTypeAdded(null);
}, 500);
}
}, [userProducts]);
return ( return (
<ScrollView style={[tw("flex flex-1 relative")]}> <ScrollView style={[tw("flex flex-1 relative")]}>
{!mobile && <View style={tw("mt-5")}></View>} {!mobile && <View style={tw("mt-5")}></View>}
{(!book || userFavoriteLoading) && ( {(!book) && (
<View <View
style={[ style={[
tw("absolute left-0 top-0 rounded-md overflow-hidden"), tw("absolute left-0 top-0 rounded-md overflow-hidden"),
@ -221,17 +266,23 @@ function Book({
onPress={() => onPress={() =>
physicalAvailabileInCart physicalAvailabileInCart
? asyncAwesomeAlert( ? asyncAwesomeAlert(
"نتیجه", "",
"این محصول قبلا به سبد خرید اضافه شده است.", "این محصول قبلا به سبد خرید شما اضافه شده است.",
{ {
showCancelButton: false, showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
} }
) )
: pushToCart({ : addToCart(
productId: book?.product[1]?.id, pushToCart({
userId: userId, productId: book?.product[1]?.id,
count: 1, userId: userId,
}) count: 1,
}),
"physical"
)
} }
> >
<> <>
@ -278,17 +329,23 @@ function Book({
onPress={() => onPress={() =>
digitalAvailabileInCart digitalAvailabileInCart
? asyncAwesomeAlert( ? asyncAwesomeAlert(
"خطا", "",
"این محصول قبلا به سبد خرید اضافه شده است.", "این محصول قبلا به سبد خرید شما اضافه شده است.",
{ {
showCancelButton: false, showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
} }
) )
: pushToCart({ : addToCart(
productId: book?.product[0]?.id, pushToCart({
userId: userId, productId: book?.product[0]?.id,
count: 1, userId: userId,
}) count: 1,
}),
"digital"
)
} }
> >
<> <>
@ -356,11 +413,25 @@ function Book({
}, },
]} ]}
onPress={() => onPress={() =>
pushToCart({ videoAvailabileInCart
productId: book?.product[2]?.id, ? asyncAwesomeAlert(
userId: userId, "",
count: 1, "این محصول قبلا به سبد خرید شما اضافه شده است.",
}) {
showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
}
)
: addToCart(
pushToCart({
productId: book?.product[2]?.id,
userId: userId,
count: 1,
}),
"video"
)
} }
> >
<> <>

@ -133,7 +133,7 @@ const User = ({ user, mobile, theme, logout }) => {
style={tw(`flex w-full ${mobile ? "mt-0" : "mt-4"}`)} style={tw(`flex w-full ${mobile ? "mt-0" : "mt-4"}`)}
onPress={() => onPress={() =>
asyncAwesomeAlert( asyncAwesomeAlert(
"نتیجه", "",
"آیا قصد خروج از حساب کاربری فعلی رو داری؟", "آیا قصد خروج از حساب کاربری فعلی رو داری؟",
{ {
showCancelButton: true, showCancelButton: true,

@ -5,6 +5,7 @@ import {
Pressable, Pressable,
TextInput, TextInput,
KeyboardAvoidingView, KeyboardAvoidingView,
ActivityIndicator,
} from "react-native"; } from "react-native";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { userFactor } from "../../../redux/actions"; import { userFactor } from "../../../redux/actions";
@ -14,13 +15,21 @@ import fontSize from "../../../constants/fontSize";
import Colors from "../../../constants/Colors"; import Colors from "../../../constants/Colors";
import tw from "tailwind-rn"; import tw from "tailwind-rn";
function Code({ codeId, setCodeId, userId, factorId, theme }) { function Code({ codeId, setCodeId, theme, loading }) {
const [value, setValue] = React.useState(codeId || ""); const [value, setValue] = React.useState(codeId || "");
const [requestFlag, setRequestFlag] = React.useState(false);
const setOff = () => { const setOff = () => {
setCodeId({ offCodeValue: value, userId: userId, id: factorId }); setRequestFlag(true);
setCodeId({ offCodeValue: value });
}; };
React.useEffect(() => {
if (!loading) {
setRequestFlag(false);
}
}, [loading]);
return ( return (
<KeyboardAvoidingView <KeyboardAvoidingView
enabled enabled
@ -33,13 +42,13 @@ function Code({ codeId, setCodeId, userId, factorId, theme }) {
]} ]}
> >
<TextInput <TextInput
onChaneText={(text) => setValue(text)} onChangeText={(text) => setValue(text)}
style={[ style={[
tw("border-0 flex-1 text-right pr-3"), tw("border-0 flex-1 text-right pr-3"),
{ fontSize: fontSize.tiny, fontFamily: "regular" }, { fontSize: fontSize.tiny, fontFamily: "regular" },
]} ]}
placeholder={"کد تخفیف دارید ؟"} placeholder={"کد تخفیف دارید ؟"}
placeholderTextColor={Colors.theme1[theme].gray20 + 'aa'} placeholderTextColor={Colors.theme1[theme].gray20 + "aa"}
/> />
<Pressable <Pressable
onPress={() => setOff()} onPress={() => setOff()}
@ -52,14 +61,22 @@ function Code({ codeId, setCodeId, userId, factorId, theme }) {
}, },
]} ]}
> >
<Text {loading && requestFlag ? (
style={[ <ActivityIndicator
tw("text-white"), size={fontSize.tiny}
{ fontSize: fontSize.tiny, fontFamily: "bold" }, color={Colors.theme1[theme].white}
]} style={tw('px-2')}
> />
ثبت کد ) : (
</Text> <Text
style={[
tw("text-white"),
{ fontSize: fontSize.tiny, fontFamily: "bold" },
]}
>
ثبت کد
</Text>
)}
</Pressable> </Pressable>
</View> </View>
</KeyboardAvoidingView> </KeyboardAvoidingView>
@ -68,9 +85,8 @@ function Code({ codeId, setCodeId, userId, factorId, theme }) {
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
codeId: state.userFactor.info?.codeId, codeId: state.userFactor.info?.codeId,
userId: state.user.status?.id, loading: state.userFactor.loading,
factorId: state.userFactor.info?.id, theme: state.publicApi.theme,
theme: state.publicApi.theme
}); });
const mapDispatchToProps = { const mapDispatchToProps = {

@ -21,7 +21,7 @@ import tw from "tailwind-rn";
const width = Dimensions.get("window").width; 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, addActionFlag, getList }) {
const [selectedProduct, setSelectedProduct] = React.useState(null); const [selectedProduct, setSelectedProduct] = React.useState(null);
const submit = async (action) => { const submit = async (action) => {
@ -30,234 +30,241 @@ function Product({ product, grades, pushToCart, loading, mobile, theme }) {
}; };
React.useEffect(() => { React.useEffect(() => {
if(!loading){ if (!loading) {
setSelectedProduct(null); setSelectedProduct(null);
} }
},[loading]); }, [loading]);
return ( return (
<View product && (
style={[ <View
tw( style={[
`flex justify-between py-2 ${ios ? "flex-row" : "flex-row-reverse"}` tw(
), `flex justify-between py-2 ${ios ? "flex-row" : "flex-row-reverse"}`
{ ),
borderBottomWidth: 1, {
borderColor: Colors.theme1[theme].grayE3, borderBottomWidth: 1,
direction: "rtl", borderColor: Colors.theme1[theme].grayE3,
}, direction: "rtl",
]} },
> ]}
<View style={tw(`flex ${ios ? "flex-row" : "flex-row-reverse"}`)}> >
<Image <View style={tw(`flex ${ios ? "flex-row" : "flex-row-reverse"}`)}>
source={{ <Image
uri: "https://dnvn.ir/api/v1/file/" + product.product.book.fileIds, source={{
}} uri:
style={[ "https://dnvn.ir/api/v1/file/" + product.product.book.fileIds,
tw(""),
{
width: mobile ? width / 5 : width / 7,
height: ((mobile ? width / 5 : width / 7) * 4) / 2.8,
},
]}
/>
<View
style={tw(`flex ${ios ? "items-start pl-3" : "items-end pr-2"}`)}
>
<Text
style={{
fontSize: mobile ? fontSize.lg : fontSize.xl4,
color: Colors.theme1[theme].green79,
marginBottom: 5,
fontFamily: "bold",
}}
>
{product?.product?.book?.name || " "}
</Text>
<Text
style={{
fontSize: mobile ? fontSize.sm : fontSize.lg,
color: Colors.theme1[theme].gray2077,
marginBottom: 3,
fontFamily: "regular",
}}
>
{"پایه" + " " + grades[product?.product?.book?.gradeId] || " "}
</Text>
<Text
style={{
fontSize: mobile ? fontSize.sm : fontSize.lg,
color: Colors.theme1[theme].gray2077,
fontFamily: "regular",
}} }}
> style={[
{product?.productType || 1 === 2 ? "نسخه فیزیکی" : "نسخه دیجیتال"} tw(""),
</Text> {
width: mobile ? width / 5 : width / 7,
height: ((mobile ? width / 5 : width / 7) * 4) / 2.8,
},
]}
/>
<View <View
style={tw( style={tw(`flex ${ios ? "items-start pl-3" : "items-end pr-2"}`)}
`flex items-center justify-center mt-4 ${
ios ? "flex-row-reverse" : "flex-row"
}`
)}
> >
<Text <Text
style={[ style={{
{ fontSize: mobile ? fontSize.lg : fontSize.xl4,
fontSize: mobile ? fontSize.xs : fontSize.tiny, color: Colors.theme1[theme].green79,
fontFamily: "regular", marginBottom: 5,
}, fontFamily: "bold",
]} }}
> >
{" " + "تومان"} {product.product.book.name || " "}
</Text> </Text>
<Text <Text
style={[ style={{
{ fontSize: mobile ? fontSize.sm : fontSize.lg,
fontSize: mobile ? fontSize.lg : fontSize.xl, color: Colors.theme1[theme].gray2077,
fontFamily: "regular", marginBottom: 3,
}, fontFamily: "regular",
]} }}
> >
{separate(product?.product?.price) || " "} {"پایه" + " " + grades[product.product.book.gradeId] || " "}
</Text> </Text>
</View> <Text
</View> style={{
</View> fontSize: mobile ? fontSize.sm : fontSize.lg,
<View color: Colors.theme1[theme].gray2077,
style={tw(`flex justify-between ${ios ? "items-end" : "items-start"}`)} fontFamily: "regular",
> }}
<AntDesign >
name="close" {product.productType || 1 === 2 ? "نسخه فیزیکی" : "نسخه دیجیتال"}
size={mobile ? 20 : 30} </Text>
color={Colors.theme1[theme].redFF1} <View
onPress={() => style={tw(
submit( `flex items-center justify-center mt-4 ${
pushToCart( ios ? "flex-row-reverse" : "flex-row"
{ }`
productId: product?.productId, )}
userId: product?.userId,
count: product?.productType === 1 ? -1 : -product?.count,
},
{},
{ id: product?.factorId }
)
)
}
/>
<View style={tw("flex items-center mt-2")}>
<View
style={tw(
`flex items-center mb-3 ${ios ? "flex-row" : "flex-row-reverse"}`
)}
>
<Pressable
onPress={() =>
submit(
pushToCart({
productId: product?.productId,
userId: product?.userId,
count: 1,
})
)
}
style={[
tw(
`rounded-md py-0 flex flex-row justify-center items-center border ${
mobile ? "px-2" : "px-3"
}`
),
{
borderColor: Colors.theme1[theme].greenCF,
},
]}
> >
<Text <Text
style={{ style={[
fontSize: mobile ? fontSize.xl : fontSize.xl4, {
color: Colors.theme1[theme].greenCF, fontSize: mobile ? fontSize.xs : fontSize.tiny,
fontFamily: "light", fontFamily: "regular",
}} },
]}
> >
+ {" " + "تومان"}
</Text> </Text>
</Pressable>
{loading && selectedProduct === product?.productId ? (
<ActivityIndicator
style={tw("mx-2")}
size="small"
color={Colors.theme1[theme].greenBA}
/>
) : (
<Text <Text
style={[ style={[
tw("mx-2.5"),
{ {
fontSize: fontSize.xl6, fontSize: mobile ? fontSize.lg : fontSize.xl,
color: Colors.theme1[theme].greenBA, fontFamily: "regular",
fontFamily: "bold",
}, },
]} ]}
> >
{product?.count} {separate(product.product.price) || " "}
</Text> </Text>
)} </View>
</View>
<Pressable </View>
onPress={() => <View
submit( style={tw(
pushToCart({ `flex justify-between ${ios ? "items-end" : "items-start"}`
productId: product?.productId, )}
userId: product?.userId, >
count: -1, <AntDesign
}) name="close"
size={mobile ? 20 : 30}
color={Colors.theme1[theme].redFF1}
onPress={() =>
submit(
pushToCart(
{
productId: product.productId,
userId: product.userId,
count: product.productType === 1 ? -1 : -product?.count,
},
{},
{ id: product.factorId }
) )
} )
style={[ }
tw( />
`rounded-md py-0 flex flex-row justify-center items-center border ${ <View style={tw("flex items-center mt-2")}>
mobile ? "px-2.5" : "px-3.5" <View
}` style={tw(
), `flex items-center mb-3 ${
{ ios ? "flex-row" : "flex-row-reverse"
borderColor: Colors.theme1[theme].greenCF, }`
}, )}
]}
> >
<Pressable
onPress={() =>
submit(
pushToCart({
productId: product.productId,
userId: product.userId,
count: 1,
})
)
}
style={[
tw(
`rounded-md py-0 flex flex-row justify-center items-center border ${
mobile ? "px-2" : "px-3"
}`
),
{
borderColor: Colors.theme1[theme].greenCF,
},
]}
>
<Text
style={{
fontSize: mobile ? fontSize.xl : fontSize.xl4,
color: Colors.theme1[theme].greenCF,
fontFamily: "light",
}}
>
+
</Text>
</Pressable>
{(loading && selectedProduct === product.productId) ? (
<ActivityIndicator
style={tw("mx-2")}
size="small"
color={Colors.theme1[theme].greenBA}
/>
) : (
<Text
style={[
tw("mx-2.5"),
{
fontSize: fontSize.xl6,
color: Colors.theme1[theme].greenBA,
fontFamily: "bold",
},
]}
>
{product.count}
</Text>
)}
<Pressable
onPress={() =>
submit(
pushToCart({
productId: product.productId,
userId: product.userId,
count: -1,
})
)
}
style={[
tw(
`rounded-md py-0 flex flex-row justify-center items-center border ${
mobile ? "px-2.5" : "px-3.5"
}`
),
{
borderColor: Colors.theme1[theme].greenCF,
},
]}
>
<Text
style={{
fontSize: mobile ? fontSize.xl : fontSize.xl4,
color: Colors.theme1[theme].greenCF,
fontFamily: "bold",
}}
>
-
</Text>
</Pressable>
</View>
<View
style={tw(
`flex items-center justify-center ${
ios ? "flex-row-reverse" : "flex-row"
}`
)}
>
<Text style={[{ fontSize: fontSize.sm, fontFamily: "regular" }]}>
{" " + "تومان"}
</Text>
<Text <Text
style={{ style={[
fontSize: mobile ? fontSize.xl : fontSize.xl4, {
color: Colors.theme1[theme].greenCF, fontSize: mobile ? fontSize.xl : fontSize.xl4,
fontFamily: "bold", fontFamily: "regular",
}} },
]}
> >
- {separate(product.product.price * product.count) || " "}
</Text> </Text>
</Pressable> </View>
</View>
<View
style={tw(
`flex items-center justify-center ${
ios ? "flex-row-reverse" : "flex-row"
}`
)}
>
<Text style={[{ fontSize: fontSize.sm, fontFamily: "regular" }]}>
{" " + "تومان"}
</Text>
<Text
style={[
{
fontSize: mobile ? fontSize.xl : fontSize.xl4,
fontFamily: "regular",
},
]}
>
{separate(product?.product?.price * product?.count) || " "}
</Text>
</View> </View>
</View> </View>
</View> </View>
</View> )
); );
} }
@ -265,10 +272,12 @@ 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,
addActionFlag: state.userProduct.addActionFlag,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {
pushToCart: userProduct.add, pushToCart: userProduct.add,
getList: userProduct.list
}; };
export default connect(mapStateToProps, mapDispatchToProps)(Product); export default connect(mapStateToProps, mapDispatchToProps)(Product);

@ -91,7 +91,7 @@ function ShoppingCart({
getFactorInfo, getFactorInfo,
loading, loading,
payFactor, payFactor,
theme theme,
}) { }) {
const navigation = useNavigation(); const navigation = useNavigation();
const [position, setPosition] = useState("100%"); const [position, setPosition] = useState("100%");
@ -109,9 +109,7 @@ function ShoppingCart({
}, [list]); }, [list]);
useEffect(() => { useEffect(() => {
if (list.length === 0) { getList();
getList();
}
getFactorInfo({ userId }); getFactorInfo({ userId });
}, []); }, []);
@ -293,7 +291,7 @@ const mapStateToProps = (state) => ({
userId: state.user.status?.id, userId: state.user.status?.id,
hasPhysical: state.userProduct.hasPhysical, hasPhysical: state.userProduct.hasPhysical,
loading: state.userProduct.loading, loading: state.userProduct.loading,
theme: state.publicApi.theme theme: state.publicApi.theme,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {

@ -11,9 +11,11 @@ import {
Text, Text,
Appearance, Appearance,
} from "react-native"; } from "react-native";
import { useNavigation } from "@react-navigation/native";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { publicApi, userProduct } from "../../redux/actions"; import { publicApi, userProduct } from "../../redux/actions";
import separate from "../../utils/separate"; import separate from "../../utils/separate";
import { asyncAwesomeAlert } from "../../utils/AsyncWrappers";
//components //components
import Navbar from "../../components/Navbar"; import Navbar from "../../components/Navbar";
@ -40,10 +42,12 @@ function Product({
pushToCart, pushToCart,
loading, loading,
mobile, mobile,
theme theme,
userProducts,
}) { }) {
const [position, setPosition] = useState("100%"); const [position, setPosition] = useState("100%");
const navigation = useNavigation();
const [addedFlag, setAddedFlag] = React.useState(false);
useEffect(() => { useEffect(() => {
getBook({ bookId: route.params.id }, { id: route.params.id, vod: true }); getBook({ bookId: route.params.id }, { id: route.params.id, vod: true });
}, []); }, []);
@ -52,6 +56,32 @@ function Product({
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
setPosition(position === "100%" ? "0%" : "100%"); setPosition(position === "100%" ? "0%" : "100%");
}; };
const videoAvailabileInCart = React.useMemo(() => {
return userProducts?.filter(
(product) => product?.productId === book?.product[2]?.id
)[0];
}, [userProducts, book]);
const addToCart = React.useCallback(
async (action) => {
setAddedFlag(true);
await action();
},
[book, userId]
);
React.useEffect(() => {
if (videoAvailabileInCart && addedFlag) {
setAddedFlag(false);
asyncAwesomeAlert("", "به سبد خرید اضافه شد", {
showCancelButton: false,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
});
}
}, [userProducts]);
return ( return (
<SafeAreaView <SafeAreaView
style={{ style={{
@ -90,7 +120,10 @@ function Product({
resizeMode="contain" resizeMode="contain"
style={[ style={[
tw("rounded-sm ml-2"), tw("rounded-sm ml-2"),
{ height: mobile ? width / 3 * 4 / 2.6 : 300, width: mobile ? width / 3 : 210 }, {
height: mobile ? ((width / 3) * 4) / 2.6 : 300,
width: mobile ? width / 3 : 210,
},
]} ]}
/> />
<View style={tw("flex items-end flex-1")}> <View style={tw("flex items-end flex-1")}>
@ -135,11 +168,24 @@ function Product({
width={"100%"} width={"100%"}
loading={loading} loading={loading}
onPress={() => onPress={() =>
pushToCart({ videoAvailabileInCart
productId: book?.product[2]?.id, ? asyncAwesomeAlert(
userId: userId, "",
count: 1, "این محصول قبلا به سبد خرید شما اضافه شده است.",
}) {
showCancelButton: true,
onConfirm: () => navigation.push("ShoppingCart"),
confirmText: "مشاهده سبد خرید",
cancelText: "باشه",
}
)
: addToCart(
pushToCart({
productId: book?.product[2]?.id,
userId: userId,
count: 1,
})
)
} }
/> />
</View> </View>
@ -170,13 +216,14 @@ const styles = StyleSheet.create({
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
book: state.book.info, book: state.book.info,
userProducts: state.userProduct.list,
seasons: state.publicApi.categories, seasons: state.publicApi.categories,
grades: state.publicApi.grades, grades: state.publicApi.grades,
isLogin: state.user.status, isLogin: state.user.status,
userId: state.user.status?.id, userId: state.user.status?.id,
loading: state.userProduct.loading, loading: state.userProduct.loading,
mobile: state.publicApi.mobile, mobile: state.publicApi.mobile,
theme: state.publicApi.theme theme: state.publicApi.theme,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {

@ -31,7 +31,6 @@ const ios = Platform.OS === "ios";
function VideoDisplay({ route, mobile, theme }) { function VideoDisplay({ route, mobile, theme }) {
const video = React.useRef(null); const video = React.useRef(null);
const [width, setWidth] = useState(Dimensions.get("window").width); const [width, setWidth] = useState(Dimensions.get("window").width);
const [status, setStatus] = React.useState({});
const [position, setPosition] = useState("100%"); const [position, setPosition] = useState("100%");
const setBoxPosition = () => { const setBoxPosition = () => {
@ -39,15 +38,7 @@ function VideoDisplay({ route, mobile, theme }) {
setPosition(position === "100%" ? "0%" : "100%"); setPosition(position === "100%" ? "0%" : "100%");
}; };
const setOrientation = () => { console.log(video);
if (Dimensions.get("window").height > Dimensions.get("window").width) {
//Device is in portrait mode, rotate to landscape mode.
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE);
} else {
//Device is in landscape mode, rotate to portrait mode.
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT);
}
}
return ( return (
<SafeAreaView <SafeAreaView
@ -79,15 +70,13 @@ function VideoDisplay({ route, mobile, theme }) {
<View style={tw("flex ")}> <View style={tw("flex ")}>
<Video <Video
ref={video} ref={video}
style={{ width: "100%", height: (width * 9) / 16 - 16 }} style={{ width: "100%", height: (width * 9) / 16 - 16}}
source={{ source={{
uri: `https://dnvn.ir/api/v1/file/${route.params.unit?.fileIds}`, uri: `https://dnvn.ir/api/v1/file/${route.params.unit?.fileIds}`,
}} }}
useNativeControls useNativeControls
resizeMode="cover" resizeMode="cover"
onFullscreenUpdate={setOrientation}
isLooping
onPlaybackStatusUpdate={(status) => setStatus(() => status)}
/> />
<Text <Text
style={{ style={{

Loading…
Cancel
Save