reza added addFavorite and delete favorite in Book component

master
Reza_ashrafi 3 years ago
parent 7aed7b068d
commit 57758441e0
  1. 75
      src/components/Navbar.js
  2. 2
      src/screens/Blog/index.js
  3. 12
      src/screens/Product/components/Book.js

@ -32,9 +32,20 @@ const Navbar = ({
setBoxPosition, setBoxPosition,
headerOptions, headerOptions,
addToBookmark, addToBookmark,
deleteBookmark,
userFavoriteList,
}) => { }) => {
const navigation = useNavigation(); const navigation = useNavigation();
const colorScheme = Appearance.getColorScheme(); const colorScheme = Appearance.getColorScheme();
const isActiveBookmark = React.useMemo(() => {
return userFavoriteList.filter((object) =>
headerOptions.bookmarkItem?.productId
? object.productId === headerOptions.bookmarkItem?.productId
: object.contentId === headerOptions.bookmarkItem?.contentId
).length;
}, [headerOptions, userFavoriteList]);
const Button = useCallback(({ icon, route }) => { const Button = useCallback(({ icon, route }) => {
return ( return (
<TouchableOpacity <TouchableOpacity
@ -242,23 +253,48 @@ const Navbar = ({
/> />
</> </>
)} )}
{headerOptions?.bookmark && ( {headerOptions?.bookmark &&
<Ionicons (isActiveBookmark ? (
name="bookmark-outline" <Ionicons
style={tw("mr-2")} name="bookmark"
size={24} style={tw("mr-2")}
color={"#52796F"} size={24}
onPress={() => color={"#52796F"}
headerOptions?.bookmarkItem?.contentId onPress={() =>
? addToBookmark({ headerOptions?.bookmarkItem?.contentId
contentId: headerOptions?.bookmarkItem?.contentId, ? deleteBookmark({
}) id: userFavoriteList.filter(
: addToBookmark({ (object) =>
productId: headerOptions?.bookmarkItem?.productId, object.contentId ===
}) headerOptions.bookmarkItem?.contentId
} )[0].id,
/> })
)} : deleteBookmark({
id: userFavoriteList.filter(
(object) =>
object.productId ===
headerOptions.bookmarkItem?.productId
)[0].id,
})
}
/>
) : (
<Ionicons
name="bookmark-outline"
style={tw("mr-2")}
size={24}
color={"#52796F"}
onPress={() =>
headerOptions?.bookmarkItem?.contentId
? addToBookmark({
contentId: headerOptions?.bookmarkItem?.contentId,
})
: addToBookmark({
productId: headerOptions?.bookmarkItem?.productId,
})
}
/>
))}
{headerOptions?.menu && ( {headerOptions?.menu && (
<Entypo name="dots-three-vertical" size={24} color="#52796F" /> <Entypo name="dots-three-vertical" size={24} color="#52796F" />
)} )}
@ -267,10 +303,13 @@ const Navbar = ({
); );
}; };
const mapStateToProps = (state) => ({}); const mapStateToProps = (state) => ({
userFavoriteList: state.userFavorite.list,
});
const mapDispatchToProps = { const mapDispatchToProps = {
addToBookmark: userFavorite.add, addToBookmark: userFavorite.add,
deleteBookmark: userFavorite.del,
}; };
export default connect(mapStateToProps, mapDispatchToProps)(Navbar); export default connect(mapStateToProps, mapDispatchToProps)(Navbar);

@ -10,12 +10,14 @@ import {
Platform, Platform,
Dimensions, Dimensions,
Appearance, Appearance,
StatusBar
} from "react-native"; } from "react-native";
import { WebView } from "react-native-webview"; import { WebView } from "react-native-webview";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { blog, publicApi } from "../../redux/actions"; import { blog, publicApi } from "../../redux/actions";
import { LinearGradient } from "expo-linear-gradient"; import { LinearGradient } from "expo-linear-gradient";
//components
import Hashtags from "../Blogs/layouts/Hashtags"; import Hashtags from "../Blogs/layouts/Hashtags";
import Header from "../Blogs/layouts/Header"; import Header from "../Blogs/layouts/Header";
import New from "../Blogs/layouts/New"; import New from "../Blogs/layouts/New";

@ -41,7 +41,8 @@ function Book({
grades, grades,
pushToCart, pushToCart,
userId, userId,
loading, userProductsLoading,
userFavoriteLoading,
mobile, mobile,
userProducts, userProducts,
}) { }) {
@ -72,7 +73,7 @@ function Book({
> >
{!mobile && <View style={tw("mt-5")}></View>} {!mobile && <View style={tw("mt-5")}></View>}
{!book && ( {(!book || userFavoriteLoading ) && (
<View <View
style={[ style={[
tw("absolute left-0 top-0 rounded-md overflow-hidden"), tw("absolute left-0 top-0 rounded-md overflow-hidden"),
@ -294,7 +295,7 @@ function Book({
+ +
</Text> </Text>
</Pressable> </Pressable>
{loading ? ( {userProductsLoading ? (
<ActivityIndicator <ActivityIndicator
style={tw("mx-1.5 my-3")} style={tw("mx-1.5 my-3")}
size="small" size="small"
@ -432,7 +433,7 @@ function Book({
+ +
</Text> </Text>
</Pressable> </Pressable>
{loading ? ( {userProductsLoading ? (
<ActivityIndicator <ActivityIndicator
style={tw("mx-1.5 my-3")} style={tw("mx-1.5 my-3")}
size="small" size="small"
@ -637,7 +638,8 @@ function Book({
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
userProducts: state.userProduct.list, userProducts: state.userProduct.list,
userId: state.user.status?.id, userId: state.user.status?.id,
loading: state.userProduct.loading, userProductsLoading: state.userProduct.loading,
userFavoriteLoading : state.userFavorite.loading,
mobile: state.publicApi.mobile, mobile: state.publicApi.mobile,
}); });

Loading…
Cancel
Save