reza added addFavorite and delete favorite in Book component

master
Reza_ashrafi 3 years ago
parent 7aed7b068d
commit 57758441e0
  1. 45
      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,
headerOptions,
addToBookmark,
deleteBookmark,
userFavoriteList,
}) => {
const navigation = useNavigation();
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 }) => {
return (
<TouchableOpacity
@ -242,7 +253,32 @@ const Navbar = ({
/>
</>
)}
{headerOptions?.bookmark && (
{headerOptions?.bookmark &&
(isActiveBookmark ? (
<Ionicons
name="bookmark"
style={tw("mr-2")}
size={24}
color={"#52796F"}
onPress={() =>
headerOptions?.bookmarkItem?.contentId
? deleteBookmark({
id: userFavoriteList.filter(
(object) =>
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")}
@ -258,7 +294,7 @@ const Navbar = ({
})
}
/>
)}
))}
{headerOptions?.menu && (
<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 = {
addToBookmark: userFavorite.add,
deleteBookmark: userFavorite.del,
};
export default connect(mapStateToProps, mapDispatchToProps)(Navbar);

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

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

Loading…
Cancel
Save