diff --git a/src/components/Drawer.js b/src/components/Drawer.js index 22bcd12..78608ae 100644 --- a/src/components/Drawer.js +++ b/src/components/Drawer.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 ( { ), ]} > - + { +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 }) => { {notification && ( )} @@ -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); diff --git a/src/redux/actions/index.js b/src/redux/actions/index.js index 1ebf7bb..952f800 100644 --- a/src/redux/actions/index.js +++ b/src/redux/actions/index.js @@ -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"; diff --git a/src/redux/actions/userFavorite.js b/src/redux/actions/userFavorite.js new file mode 100644 index 0000000..fb140d1 --- /dev/null +++ b/src/redux/actions/userFavorite.js @@ -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; \ No newline at end of file diff --git a/src/redux/reducers/book.js b/src/redux/reducers/book.js index c8e6d19..897521d 100644 --- a/src/redux/reducers/book.js +++ b/src/redux/reducers/book.js @@ -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; diff --git a/src/redux/reducers/index.js b/src/redux/reducers/index.js index 53bd961..f0238b9 100644 --- a/src/redux/reducers/index.js +++ b/src/redux/reducers/index.js @@ -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"; diff --git a/src/redux/reducers/product.js b/src/redux/reducers/product.js index 23cb8fc..e1c7ddf 100644 --- a/src/redux/reducers/product.js +++ b/src/redux/reducers/product.js @@ -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; diff --git a/src/redux/reducers/userAddress.js b/src/redux/reducers/userAddress.js index d6041ff..00ad9a9 100644 --- a/src/redux/reducers/userAddress.js +++ b/src/redux/reducers/userAddress.js @@ -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": diff --git a/src/redux/reducers/userFactor.js b/src/redux/reducers/userFactor.js index ffcdac1..9791495 100644 --- a/src/redux/reducers/userFactor.js +++ b/src/redux/reducers/userFactor.js @@ -1,4 +1,3 @@ -import {useNavigation} from '@react-navigation/native'; import {asyncAwesomeAlert} from '../../utils/AsyncWrappers'; const initialState = { diff --git a/src/redux/reducers/userFavorite.js b/src/redux/reducers/userFavorite.js new file mode 100644 index 0000000..730a70e --- /dev/null +++ b/src/redux/reducers/userFavorite.js @@ -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; + } +} diff --git a/src/redux/store.js b/src/redux/store.js index b1b2138..58e0b9c 100644 --- a/src/redux/store.js +++ b/src/redux/store.js @@ -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, diff --git a/src/screens/Blog/index.js b/src/screens/Blog/index.js index 6c1a6bf..023ccce 100644 --- a/src/screens/Blog/index.js +++ b/src/screens/Blog/index.js @@ -55,6 +55,7 @@ export const Blog = ({ getInfo, blog, getList, blogs, route }) => { bookmark: true, qr: false, back: true, + bookmarkItem: { contentId: blog?.id }, }} /> + {!mobile && } - {pageLoading && ( - - + )} {imageSlider && } diff --git a/src/screens/Product/index.js b/src/screens/Product/index.js index 20f196d..4218204 100644 --- a/src/screens/Product/index.js +++ b/src/screens/Product/index.js @@ -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 }, }} /> diff --git a/src/screens/Profile/components/ProfileBookmark/index.js b/src/screens/Profile/components/ProfileBookmark/index.js index 7474fbc..f019768 100644 --- a/src/screens/Profile/components/ProfileBookmark/index.js +++ b/src/screens/Profile/components/ProfileBookmark/index.js @@ -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,76 +32,11 @@ 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 }) => { - const Bookmark = ({ bookmark }) => { - return ( - - - - - - {bookmark.name} - - - {bookmark.grade} - - - - - - - - - ); - }; + React.useEffect(() => { + getList(); + },[]); return ( { ); }; +const Bookmark = ({ bookmark }) => { + const colorScheme = Appearance.getColorScheme(); + return ( + + + + + + {bookmark.name} + + + {bookmark.grade} + + + + + + + + + ); +}; + 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); diff --git a/src/screens/VideoDisplay/index.js b/src/screens/VideoDisplay/index.js index 7ebee11..90331bd 100644 --- a/src/screens/VideoDisplay/index.js +++ b/src/screens/VideoDisplay/index.js @@ -66,7 +66,7 @@ function VideoDisplay({ route, mobile }) { menu: true, hamburgerMenu: false, title: "", - bookmark: true, + bookmark: false, qr: false, back: true, }}