reza connected userFavorite add

temp
Reza_ashrafi 3 years ago
parent 5a84cdb19a
commit 0fcd6202d0
  1. 15
      src/components/Navbar/index.js

@ -1,7 +1,8 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Link, useNavigate } from "react-router-dom"; import { Link, useNavigate } from "react-router-dom";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { userProduct } from "../../redux/actions"; import { userProduct, userFavorite } from "../../redux/actions";
import location from "../../utils/location";
import _ from "lodash"; import _ from "lodash";
//components //components
@ -34,6 +35,7 @@ function Navbar({
isMobile, isMobile,
isLogin, isLogin,
headerOptions, headerOptions,
addToFavorite,
}) { }) {
const navigation = useNavigate(); const navigation = useNavigate();
const { logo, hamburgerMenu, qr, shown, menu, title, back, bookmark } = const { logo, hamburgerMenu, qr, shown, menu, title, back, bookmark } =
@ -58,7 +60,6 @@ function Navbar({
} }
}, []); }, []);
useEffect(() => { useEffect(() => {
if (!isMobile && isLogin) { if (!isMobile && isLogin) {
getCartProducts(); getCartProducts();
@ -124,7 +125,9 @@ function Navbar({
className={_.join( className={_.join(
[ [
"rounded-sm p-1.5", "rounded-sm p-1.5",
isDark ? "bg-blueC0 bg-opacity-10 ml-2" : " ml-3 shadow-sm", isDark
? "bg-blueC0 bg-opacity-10 ml-2"
: " ml-3 shadow-sm",
], ],
" " " "
)} )}
@ -165,14 +168,15 @@ function Navbar({
isDark ? bookmarkDeactiveDarkIcon : bookmarkDeactiveLightIcon isDark ? bookmarkDeactiveDarkIcon : bookmarkDeactiveLightIcon
} }
alt="bookmark" alt="bookmark"
className="w-7 ml-2" className="w-7"
onClick={() => addToFavorite({ [bookmark]: location.getId() })}
/> />
)} )}
{menu && ( {menu && (
<img <img
src={isDark ? dotsMenuDarkIcon : dotsMenuLightIcon} src={isDark ? dotsMenuDarkIcon : dotsMenuLightIcon}
alt="menu" alt="menu"
className="w-7" className="w-7 mr-2"
/> />
)} )}
{title && back ? ( {title && back ? (
@ -288,6 +292,7 @@ const mapStateToProps = (state) => ({
const mapDispatchToProps = { const mapDispatchToProps = {
getCartProducts: userProduct.list, getCartProducts: userProduct.list,
addToFavorite: userFavorite.add,
}; };
export default connect(mapStateToProps, mapDispatchToProps)(Navbar); export default connect(mapStateToProps, mapDispatchToProps)(Navbar);

Loading…
Cancel
Save