reza connected userFavorite to app

master
Reza_ashrafi 3 years ago
parent 7ec9df4452
commit 7b16deabe0
  1. 4
      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. 4
      src/screens/Product/index.js
  15. 85
      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 }) => {

@ -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")]}>

@ -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,11 +32,49 @@ 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(); React.useEffect(() => {
getList();
},[]);
return (
<SafeAreaView
style={{
paddingTop: Platform.OS === "android" ? StatusBar.currentHeight : 0,
position: "relative",
backgroundColor: "white",
}}
>
<Navbar
headerOptions={{
logo: false,
menu: false,
hamburgerMenu: false,
title: "لیست علاقهمندیها",
bookmark: false,
qr: false,
back: true,
}}
/>
<ScrollView
contentContainerStyle={styles.contentContainerStyle}
style={styles.container}
>
<View style={tw("w-full mt-2 px-4")}>
<View style={tw("p-0 m-0 flex ")}>
{bookmarkList.map((bookmark, index) => (
<Bookmark key={index} bookmark={bookmark} />
))}
</View>
</View>
</ScrollView>
</SafeAreaView>
);
};
const Bookmark = ({ bookmark }) => { const Bookmark = ({ bookmark }) => {
const colorScheme = Appearance.getColorScheme();
return ( return (
<Pressable <Pressable
style={[ style={[
@ -102,47 +141,15 @@ const ProfileBookmark = ({ bookmarkList }) => {
); );
}; };
return (
<SafeAreaView
style={{
paddingTop: Platform.OS === "android" ? StatusBar.currentHeight : 0,
position: "relative",
backgroundColor: "white",
}}
>
<Navbar
headerOptions={{
logo: false,
menu: false,
hamburgerMenu: false,
title: "لیست علاقهمندیها",
bookmark: false,
qr: false,
back: true,
}}
/>
<ScrollView
contentContainerStyle={styles.contentContainerStyle}
style={styles.container}
>
<View style={tw("w-full mt-2 px-4")}>
<View style={tw("p-0 m-0 flex ")}>
{bookmarkList.map((bookmark, index) => (
<Bookmark key={index} bookmark={bookmark} />
))}
</View>
</View>
</ScrollView>
</SafeAreaView>
);
};
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