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

@ -1,7 +1,11 @@
import React, { useCallback } from "react";
import { StyleSheet, View, Pressable, Text, Appearance, TouchableOpacity } from "react-native";
import { useNavigation } from "@react-navigation/native";
import { Ionicons, Entypo } from "@expo/vector-icons";
import {
View,
Pressable,
Text,
Appearance,
TouchableOpacity,
} from "react-native";
import Svg, {
G,
Defs,
@ -11,14 +15,24 @@ import Svg, {
Text as Textt,
TSpan,
} from "react-native-svg";
import { useNavigation } from "@react-navigation/native";
import { Ionicons, Entypo } from "@expo/vector-icons";
import { connect } from "react-redux";
import { userFavorite } from "../redux/actions";
//style
import Color from "../constants/Colors";
import tw from "tailwind-rn";
import fontSize from "../constants/fontSize";
const Navbar = ({ notification, setBoxPosition, headerOptions }) => {
const Navbar = ({
notification,
setBoxPosition,
headerOptions,
addToBookmark,
}) => {
const navigation = useNavigation();
const colorScheme = Appearance.getColorScheme();
const Button = useCallback(({ icon, route }) => {
@ -27,7 +41,7 @@ const Navbar = ({ notification, setBoxPosition, headerOptions }) => {
style={[
tw("rounded-md p-1"),
{
backgroundColor: Color.theme1[colorScheme].greenCF + '05',
backgroundColor: Color.theme1[colorScheme].greenCF + "05",
borderColor: Color.theme1[colorScheme].green79,
borderWidth: 1,
marginLeft: route === "AR" ? 10 : 0,
@ -97,9 +111,7 @@ const Navbar = ({ notification, setBoxPosition, headerOptions }) => {
</Svg>
{notification && (
<View
style={tw(
"h-2.5 w-2.5 absolute -left-1 -top-1 rounded-full"
)}
style={tw("h-2.5 w-2.5 absolute -left-1 -top-1 rounded-full")}
></View>
)}
</Pressable>
@ -236,7 +248,15 @@ const Navbar = ({ notification, setBoxPosition, headerOptions }) => {
style={tw("mr-2")}
size={24}
color={"#52796F"}
onPress={() => navigation.goBack()}
onPress={() =>
headerOptions?.bookmarkItem?.contentId
? addToBookmark({
contentId: headerOptions?.bookmarkItem?.contentId,
})
: addToBookmark({
productId: headerOptions?.bookmarkItem?.productId,
})
}
/>
)}
{headerOptions?.menu && (
@ -249,6 +269,8 @@ const Navbar = ({ notification, setBoxPosition, headerOptions }) => {
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 qr } from "./qr";
export {default as userAddress} from "./userAddress";
export {default as userFavorite} from "./userFavorite";
export { default as transport } from "./transport";
export { default as activation } from "./activation";
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 = {
loading: false,
error: null,
@ -83,7 +85,9 @@ export default function book(state = initialState, action) {
case "book/loading":
return { ...state, loading: true };
case "book/error":
// toast.error(data.message);
asyncAwesomeAlert("خطا", data.message, {
showCancelButton: false,
});
return { ...state, loading: false, error: data.message };
default:
return state;

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

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

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

@ -1,4 +1,3 @@
import {useNavigation} from '@react-navigation/native';
import {asyncAwesomeAlert} from '../../utils/AsyncWrappers';
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 comment from './reducers/comment';
import form from "./reducers/form";
import userFavorite from "./reducers/userFavorite";
const persistConfig = {
key: "root",
@ -52,7 +53,8 @@ const store = createStore(
userAddress,
transport,
comment,
form
form,
userFavorite
})
),
initialState,

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

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

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

@ -16,6 +16,7 @@ import React from "react";
import { connect } from "react-redux";
import { useNavigation } from "@react-navigation/native";
import Svg, { Path } from "react-native-svg";
import {userFavorite} from '../../../../redux/actions';
//components
import Navbar from "../../../../components/Navbar";
@ -31,11 +32,49 @@ import bookImage from "../../..//OrdersFollowUp/assets/b1.png";
const { height, width } = Dimensions.get("window");
const ios = Platform.OS === "ios";
const ProfileBookmark = ({ bookmarkList }) => {
const colorScheme = Appearance.getColorScheme();
const navigation = useNavigation();
const ProfileBookmark = ({ bookmarkList, getList }) => {
React.useEffect(() => {
getList();
},[]);
const Bookmark = ({ bookmark }) => {
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 colorScheme = Appearance.getColorScheme();
return (
<Pressable
style={[
@ -100,49 +139,17 @@ const ProfileBookmark = ({ bookmarkList }) => {
</Svg>
</Pressable>
);
};
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) => ({
loading: state.userFactor.loading,
mobile: state.publicApi.mobile,
bookmarkList : state.userFavorite.list
});
const mapDispatchToProps = {};
const mapDispatchToProps = {
getList : userFavorite.list,
};
export default connect(mapStateToProps, mapDispatchToProps)(ProfileBookmark);

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

Loading…
Cancel
Save