You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

138 lines
3.5 KiB

import {
View,
Text,
Image,
Pressable,
FlatList,
Platform,
Linking,
Dimensions,
} from "react-native";
import { connect } from "react-redux";
//components
import Progress from "../../../components/Progress";
//Color
import Colors from "../../../constants/Colors";
import tw from "tailwind-rn";
import fontSize from "../../../constants/fontSize";
const ios = Platform.OS === "ios";
const { width, height } = Dimensions.get("window");
function MyBooks({ books, grades, theme, mobile }) {
return books?.filter(
(book) =>
(book?.productType === 2 || book?.productType === 3) &&
book?.condition >= 2
).length ? (
<View style={[tw("flex w-full mb-5")]}>
<View
style={[
tw(`w-full flex rounded-md pt-3 overflow-hidden`),
{
backgroundColor:
theme === "light"
? Colors.theme1.greenCF + "0F"
: Colors.theme1.greenCF + "11",
borderColor:
Colors.theme1.greenD9 + (theme === "light" ? "" : "77"),
borderWidth: 1,
},
]}
>
<Text
style={[
tw(`pr-4 ${ios ? "text-right" : ""} w-full`),
{
color:
theme === "light" ? Colors.theme1.green79 : Colors.theme1.white,
fontFamily: "demi",
fontSize: fontSize.lg,
},
]}
>
کتابهای من
</Text>
<FlatList
showsHorizontalScrollIndicator={false}
style={[tw("py-3")]}
horizontal={true}
inverted={true}
data={books?.filter((book) => book?.condition >= 2)}
renderItem={({ item }) => (
<Book book={item} grades={grades} theme={theme} mobile={mobile} />
)}
keyExtractor={(book) => book?.id}
/>
</View>
</View>
) : null;
}
const Book = ({ book, grades, theme, mobile }) => {
const actions = {
3: () =>
Linking.openURL(`https://ar.dnvn.ir/lunch?id=${book?.product?.ARId}`),
2: () =>
Linking.openURL(`https://ar.dnvn.ir/lunch?id=${book?.product?.ARId}`),
4: () => {},
};
return (
<Pressable
style={tw(`flex mr-4 ${ios ? "items-end" : ""}`)}
onPress={actions[book?.productType]}
>
<View style={{ height: mobile ? 165 : height / 5 }}>
<Image
source={{
uri: `https://dnvn.ir/api/v1/file/${book?.product?.book?.fileIds}`,
}}
resizeMode="contain"
style={[
{
width: mobile ? 110 : height / 5 * 3 / 4,
flex: 1,
},
]}
/>
</View>
<Text
style={[
tw("mt-2 pr-1"),
{
color:
theme === "light" ? Colors.theme1.gray20 : Colors.theme1.white,
fontFamily: "bold",
fontSize: fontSize.tiny,
},
]}
>
{book?.name}
</Text>
<Text
style={[
tw("pr-1"),
{
color:
theme === "light" ? Colors.theme1.gray20 : Colors.theme1.white,
fontFamily: "light",
fontSize: fontSize.sm,
},
]}
>
{"پایه" + " " + grades[book?.product?.book?.gradeId]}
</Text>
<Progress percent={60} alignItems={"items-end"} />
</Pressable>
);
};
const mapStateToProps = (state) => ({
grades: state.publicApi.grades,
theme: state.publicApi.theme,
mobile: state.publicApi.mobile,
});
export default connect(mapStateToProps)(MyBooks);