reza connected userFavorite to app

master
Reza_ashrafi 3 years ago
parent 7ec9df4452
commit 7b16deabe0
  1. 8
      src/components/Drawer.js
  2. 44
      src/components/Navbar.js
  3. 1
      src/redux/actions/index.js
  4. 29
      src/redux/actions/userFavorite.js
  5. 6
      src/redux/reducers/book.js
  6. 1
      src/redux/reducers/index.js
  7. 6
      src/redux/reducers/product.js
  8. 2
      src/redux/reducers/userAddress.js
  9. 1
      src/redux/reducers/userFactor.js
  10. 29
      src/redux/reducers/userFavorite.js
  11. 4
      src/redux/store.js
  12. 1
      src/screens/Blog/index.js
  13. 13
      src/screens/Product/components/Book.js
  14. 6
      src/screens/Product/index.js
  15. 147
      src/screens/Profile/components/ProfileBookmark/index.js
  16. 2
      src/screens/VideoDisplay/index.js

@ -39,7 +39,7 @@ const Drawer = ({ position, setBoxPosition, user, mobile }) => {
const [dropdownHeight, setDropdownHeight] = useState(0); const [dropdownHeight, setDropdownHeight] = useState(0);
const colorScheme = Appearance.getColorScheme(); const colorScheme = Appearance.getColorScheme();
const [routes, setRoutes] = useState([ const routes = [
{ {
name: "صفحه اصلی", name: "صفحه اصلی",
route: "Home", route: "Home",
@ -204,7 +204,7 @@ const Drawer = ({ position, setBoxPosition, user, mobile }) => {
toast: "", toast: "",
message: "", message: "",
}, },
]); ];
const [addUserDropdown, setAddUserDropdown] = useState(false); const [addUserDropdown, setAddUserDropdown] = useState(false);
const navigation = useNavigation(); const navigation = useNavigation();
const Route = ({ route }) => { const Route = ({ route }) => {
@ -250,7 +250,7 @@ const Drawer = ({ position, setBoxPosition, user, mobile }) => {
return ( return (
<View <View
style={[ style={[
tw(`absolute top-0 flex flex-row justify-end `), tw(`absolute top-0 flex flex-row justify-end`),
{ {
left: position, left: position,
width: width, width: width,
@ -268,7 +268,7 @@ const Drawer = ({ position, setBoxPosition, user, mobile }) => {
), ),
]} ]}
></Pressable> ></Pressable>
<View style={[tw("w-4/5 bg-white h-full flex ")]}> <View style={[tw("w-4/5 bg-white h-full flex")]}>
<View <View
style={[ style={[
tw("flex items-end pt-12 px-4"), tw("flex items-end pt-12 px-4"),

@ -1,7 +1,11 @@
import React, { useCallback } from "react"; import React, { useCallback } from "react";
import { StyleSheet, View, Pressable, Text, Appearance, TouchableOpacity } from "react-native"; import {
import { useNavigation } from "@react-navigation/native"; View,
import { Ionicons, Entypo } from "@expo/vector-icons"; Pressable,
Text,
Appearance,
TouchableOpacity,
} from "react-native";
import Svg, { import Svg, {
G, G,
Defs, Defs,
@ -11,14 +15,24 @@ import Svg, {
Text as Textt, Text as Textt,
TSpan, TSpan,
} from "react-native-svg"; } from "react-native-svg";
import { useNavigation } from "@react-navigation/native";
import { Ionicons, Entypo } from "@expo/vector-icons";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { userFavorite } from "../redux/actions";
//style //style
import Color from "../constants/Colors"; import Color from "../constants/Colors";
import tw from "tailwind-rn"; import tw from "tailwind-rn";
import fontSize from "../constants/fontSize"; import fontSize from "../constants/fontSize";
const Navbar = ({ notification, setBoxPosition, headerOptions }) => { const Navbar = ({
notification,
setBoxPosition,
headerOptions,
addToBookmark,
}) => {
const navigation = useNavigation(); const navigation = useNavigation();
const colorScheme = Appearance.getColorScheme(); const colorScheme = Appearance.getColorScheme();
const Button = useCallback(({ icon, route }) => { const Button = useCallback(({ icon, route }) => {
@ -27,7 +41,7 @@ const Navbar = ({ notification, setBoxPosition, headerOptions }) => {
style={[ style={[
tw("rounded-md p-1"), tw("rounded-md p-1"),
{ {
backgroundColor: Color.theme1[colorScheme].greenCF + '05', backgroundColor: Color.theme1[colorScheme].greenCF + "05",
borderColor: Color.theme1[colorScheme].green79, borderColor: Color.theme1[colorScheme].green79,
borderWidth: 1, borderWidth: 1,
marginLeft: route === "AR" ? 10 : 0, marginLeft: route === "AR" ? 10 : 0,
@ -97,9 +111,7 @@ const Navbar = ({ notification, setBoxPosition, headerOptions }) => {
</Svg> </Svg>
{notification && ( {notification && (
<View <View
style={tw( style={tw("h-2.5 w-2.5 absolute -left-1 -top-1 rounded-full")}
"h-2.5 w-2.5 absolute -left-1 -top-1 rounded-full"
)}
></View> ></View>
)} )}
</Pressable> </Pressable>
@ -236,7 +248,15 @@ const Navbar = ({ notification, setBoxPosition, headerOptions }) => {
style={tw("mr-2")} style={tw("mr-2")}
size={24} size={24}
color={"#52796F"} color={"#52796F"}
onPress={() => navigation.goBack()} onPress={() =>
headerOptions?.bookmarkItem?.contentId
? addToBookmark({
contentId: headerOptions?.bookmarkItem?.contentId,
})
: addToBookmark({
productId: headerOptions?.bookmarkItem?.productId,
})
}
/> />
)} )}
{headerOptions?.menu && ( {headerOptions?.menu && (
@ -249,6 +269,8 @@ const Navbar = ({ notification, setBoxPosition, headerOptions }) => {
const mapStateToProps = (state) => ({}); const mapStateToProps = (state) => ({});
export default connect(mapStateToProps)(Navbar); const mapDispatchToProps = {
addToBookmark: userFavorite.add,
};
const styles = StyleSheet.create({}); export default connect(mapStateToProps, mapDispatchToProps)(Navbar);

@ -11,6 +11,7 @@ export { default as faq } from "./faq";
export { default as file } from "./file"; export { default as file } from "./file";
export { default as qr } from "./qr"; export { default as qr } from "./qr";
export {default as userAddress} from "./userAddress"; export {default as userAddress} from "./userAddress";
export {default as userFavorite} from "./userFavorite";
export { default as transport } from "./transport"; export { default as transport } from "./transport";
export { default as activation } from "./activation"; export { default as activation } from "./activation";
export { default as form } from "./form"; export { default as form } from "./form";

@ -0,0 +1,29 @@
import proxy from "../proxy";
const userFavorite = {
list:
(data = {}) =>
async (dispatch) => {
await proxy.get("userFavorite/list", data, { dispatch });
},
update:
(data = {}, data2 = {}) =>
async (dispatch) => {
await proxy.put("userFavorite/update", data);
await proxy.get("userFavorite/list", data2, { dispatch });
},
add:
(data = {}, data2 = {}, data3 = {}) =>
async (dispatch) => {
await proxy.post("userFavorite/add", data, { dispatch });
await proxy.get("userFavorite/list", data2, { dispatch });
},
del:
(data = {}, data2 = {}) =>
async (dispatch) => {
await proxy.delete("userFavorite/delete", data);
await proxy.get("userFavorite/list", data2, { dispatch });
},
};
export default userFavorite;

@ -1,3 +1,5 @@
import {asyncAwesomeAlert} from '../../utils/AsyncWrappers';
const initialState = { const initialState = {
loading: false, loading: false,
error: null, error: null,
@ -83,7 +85,9 @@ export default function book(state = initialState, action) {
case "book/loading": case "book/loading":
return { ...state, loading: true }; return { ...state, loading: true };
case "book/error": case "book/error":
// toast.error(data.message); asyncAwesomeAlert("خطا", data.message, {
showCancelButton: false,
});
return { ...state, loading: false, error: data.message }; return { ...state, loading: false, error: data.message };
default: default:
return state; return state;

@ -10,6 +10,7 @@ export { default as userFactor } from "./userFactor";
export { default as userProduct } from "./userProduct"; export { default as userProduct } from "./userProduct";
import { default as qr } from "./qr"; import { default as qr } from "./qr";
export { default as userAddress } from "./userAddress"; export { default as userAddress } from "./userAddress";
export { default as userFavorite } from "./userFavorite";
export { default as transport } from "./transport"; export { default as transport } from "./transport";
export { default as activation } from "./activation"; export { default as activation } from "./activation";
export { default as form } from "./form"; export { default as form } from "./form";

@ -1,3 +1,5 @@
import {asyncAwesomeAlert} from '../../utils/AsyncWrappers';
const initialState = { const initialState = {
loading: false, loading: false,
error: null, error: null,
@ -18,7 +20,9 @@ export default function product(state = initialState, action) {
case "product/loading": case "product/loading":
return { ...state, loading: true }; return { ...state, loading: true };
case "product/error": case "product/error":
// toast.error(data.message); asyncAwesomeAlert("خطا", data.message, {
showCancelButton: false,
});
return { ...state, loading: false, error: data.message }; return { ...state, loading: false, error: data.message };
default: default:
return state; return state;

@ -19,7 +19,7 @@ export default function userAddress(state = initialState, action) {
case "userAddress/update": case "userAddress/update":
return { ...state, loading: false, error: null }; return { ...state, loading: false, error: null };
case "userAddress/add": case "userAddress/add":
return { ...state, loading: false, error: null, sum: data.payPrice }; return { ...state, loading: false, error: null};
case "userAddress/delete": case "userAddress/delete":
return { ...state, loading: false, error: null }; return { ...state, loading: false, error: null };
case "userAddress/loading": case "userAddress/loading":

@ -1,4 +1,3 @@
import {useNavigation} from '@react-navigation/native';
import {asyncAwesomeAlert} from '../../utils/AsyncWrappers'; import {asyncAwesomeAlert} from '../../utils/AsyncWrappers';
const initialState = { const initialState = {

@ -0,0 +1,29 @@
const initialState = {
loading: false,
error: null,
list: [],
};
export default function userAddress(state = initialState, action) {
let { type, data } = action;
switch (type) {
case "userAddress/list":
return {
...state,
loading: false,
list: data,
error: null,
};
case "userAddress/update":
return { ...state, loading: false, error: null };
case "userAddress/add":
return { ...state, loading: false, error: null };
case "userAddress/delete":
return { ...state, loading: false, error: null };
case "userAddress/loading":
return { ...state, loading: true };
case "userAddress/error":
return { ...state, loading: false, error: data.message };
default:
return state;
}
}

@ -18,6 +18,7 @@ import userAddress from "./reducers/userAddress";
import transport from "./reducers/transport" import transport from "./reducers/transport"
import comment from './reducers/comment'; import comment from './reducers/comment';
import form from "./reducers/form"; import form from "./reducers/form";
import userFavorite from "./reducers/userFavorite";
const persistConfig = { const persistConfig = {
key: "root", key: "root",
@ -52,7 +53,8 @@ const store = createStore(
userAddress, userAddress,
transport, transport,
comment, comment,
form form,
userFavorite
}) })
), ),
initialState, initialState,

@ -55,6 +55,7 @@ export const Blog = ({ getInfo, blog, getList, blogs, route }) => {
bookmark: true, bookmark: true,
qr: false, qr: false,
back: true, back: true,
bookmarkItem: { contentId: blog?.id },
}} }}
/> />
<ScrollView <ScrollView

@ -67,22 +67,25 @@ function Book({
)[0]; )[0];
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>}
{pageLoading && ( {!book && (
<Pressable <View
style={[ style={[
tw("absolute left-0 top-0 rounded-md overflow-hidden"), tw("absolute left-0 top-0 rounded-md overflow-hidden"),
{ {
width: Dimensions.get("window").width, width: Dimensions.get("window").width,
height: height - 150, height: height - 200,
zIndex: 1, zIndex: 1,
backgroundColor: Colors.theme1[colorScheme].white + "60", backgroundColor: Colors.theme1[colorScheme].white + "60",
}, },
]} ]}
> >
<Blur /> <Blur />
</Pressable> </View>
)} )}
{imageSlider && <ImageSlider />} {imageSlider && <ImageSlider />}
<View style={[tw("flex flex-row-reverse")]}> <View style={[tw("flex flex-row-reverse")]}>

@ -14,7 +14,7 @@ import Navbar from "../../components/Navbar";
function Product({ route, book, getBook, grades }) { function Product({ route, book, getBook, grades }) {
useEffect(() => { useEffect(() => {
getBook({ id: route.params.id, vod : true }); getBook({ id: route.params.id, vod: true });
}, []); }, []);
return ( return (
@ -28,17 +28,19 @@ function Product({ route, book, getBook, grades }) {
// setBoxPosition={setBoxPosition} // setBoxPosition={setBoxPosition}
headerOptions={{ headerOptions={{
logo: false, logo: false,
menu: true, menu: false,
hamburgerMenu: false, hamburgerMenu: false,
title: "", title: "",
bookmark: true, bookmark: true,
qr: false, qr: false,
back: true, back: true,
bookmarkItem: { productId: book?.id },
}} }}
/> />
<ScrollView <ScrollView
contentContainerStyle={styles.contentContainerStyle} contentContainerStyle={styles.contentContainerStyle}
style={styles.container} style={styles.container}
scrollEnabled={book ? true : false}
> >
<Book book={book} grades={grades} /> <Book book={book} grades={grades} />
</ScrollView> </ScrollView>

@ -16,6 +16,7 @@ import React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { useNavigation } from "@react-navigation/native"; import { useNavigation } from "@react-navigation/native";
import Svg, { Path } from "react-native-svg"; import Svg, { Path } from "react-native-svg";
import {userFavorite} from '../../../../redux/actions';
//components //components
import Navbar from "../../../../components/Navbar"; import Navbar from "../../../../components/Navbar";
@ -31,76 +32,11 @@ import bookImage from "../../..//OrdersFollowUp/assets/b1.png";
const { height, width } = Dimensions.get("window"); const { height, width } = Dimensions.get("window");
const ios = Platform.OS === "ios"; const ios = Platform.OS === "ios";
const ProfileBookmark = ({ bookmarkList }) => { const ProfileBookmark = ({ bookmarkList, getList }) => {
const colorScheme = Appearance.getColorScheme();
const navigation = useNavigation();
const Bookmark = ({ bookmark }) => { React.useEffect(() => {
return ( getList();
<Pressable },[]);
style={[
tw("flex flex-row-reverse rounded-md justify-between px-3.5 py-2"),
{
borderWidth: 1.5,
borderColor: Colors.theme1[colorScheme].greenCF,
},
]}
>
<View style={tw("flex flex-row-reverse items-end")}>
<Image
source={bookmark.image}
style={{
width: mobile ? width / 5 : width / 7,
minWidth: 80,
height: ((mobile ? width / 5 : width / 7) * 4) / 2.7,
minHeight: (80 * 4) / 2.7,
}}
/>
<View style={tw(`flex mr-2 ${ios ? "items-end" : ""}`)}>
<Text
style={{
fontFamily: "bold",
fontSize: fontSize.lg,
color: Colors.theme1[colorScheme].gray20,
}}
>
{bookmark.name}
</Text>
<Text
style={{
marginTop: 5,
fontFamily: "regular",
fontSize: fontSize.base,
color: Colors.theme1[colorScheme].gray20,
}}
>
{bookmark.grade}
</Text>
</View>
</View>
<Svg
data-name="vuesax/linear/archive-add"
xmlns="http://www.w3.org/2000/svg"
width={29.778}
height={29.778}
>
<Path
d="M20.869 2.482H8.908a4.8 4.8 0 0 0-4.789 4.789v17.483c0 2.233 1.6 3.176 3.561 2.1l6.055-3.362a2.628 2.628 0 0 1 2.32 0l6.055 3.362c1.96 1.092 3.561.149 3.561-2.1V7.271a4.819 4.819 0 0 0-4.802-4.789Z"
fill="#37a865"
/>
<Path
data-name="Vector"
d="M17.987 13.214h-6.2"
fill="none"
stroke="#fff"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={1.5}
/>
</Svg>
</Pressable>
);
};
return ( return (
<SafeAreaView <SafeAreaView
@ -137,12 +73,83 @@ const ProfileBookmark = ({ bookmarkList }) => {
); );
}; };
const Bookmark = ({ bookmark }) => {
const colorScheme = Appearance.getColorScheme();
return (
<Pressable
style={[
tw("flex flex-row-reverse rounded-md justify-between px-3.5 py-2"),
{
borderWidth: 1.5,
borderColor: Colors.theme1[colorScheme].greenCF,
},
]}
>
<View style={tw("flex flex-row-reverse items-end")}>
<Image
source={bookmark.image}
style={{
width: mobile ? width / 5 : width / 7,
minWidth: 80,
height: ((mobile ? width / 5 : width / 7) * 4) / 2.7,
minHeight: (80 * 4) / 2.7,
}}
/>
<View style={tw(`flex mr-2 ${ios ? "items-end" : ""}`)}>
<Text
style={{
fontFamily: "bold",
fontSize: fontSize.lg,
color: Colors.theme1[colorScheme].gray20,
}}
>
{bookmark.name}
</Text>
<Text
style={{
marginTop: 5,
fontFamily: "regular",
fontSize: fontSize.base,
color: Colors.theme1[colorScheme].gray20,
}}
>
{bookmark.grade}
</Text>
</View>
</View>
<Svg
data-name="vuesax/linear/archive-add"
xmlns="http://www.w3.org/2000/svg"
width={29.778}
height={29.778}
>
<Path
d="M20.869 2.482H8.908a4.8 4.8 0 0 0-4.789 4.789v17.483c0 2.233 1.6 3.176 3.561 2.1l6.055-3.362a2.628 2.628 0 0 1 2.32 0l6.055 3.362c1.96 1.092 3.561.149 3.561-2.1V7.271a4.819 4.819 0 0 0-4.802-4.789Z"
fill="#37a865"
/>
<Path
data-name="Vector"
d="M17.987 13.214h-6.2"
fill="none"
stroke="#fff"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={1.5}
/>
</Svg>
</Pressable>
);
};
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
loading: state.userFactor.loading, loading: state.userFactor.loading,
mobile: state.publicApi.mobile, mobile: state.publicApi.mobile,
bookmarkList : state.userFavorite.list
}); });
const mapDispatchToProps = {}; const mapDispatchToProps = {
getList : userFavorite.list,
};
export default connect(mapStateToProps, mapDispatchToProps)(ProfileBookmark); export default connect(mapStateToProps, mapDispatchToProps)(ProfileBookmark);

@ -66,7 +66,7 @@ function VideoDisplay({ route, mobile }) {
menu: true, menu: true,
hamburgerMenu: false, hamburgerMenu: false,
title: "", title: "",
bookmark: true, bookmark: false,
qr: false, qr: false,
back: true, back: true,
}} }}

Loading…
Cancel
Save