|
|
@ -1,10 +1,11 @@ |
|
|
|
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 {publicApi} from "../../redux/actions"; |
|
|
|
import { userProduct } from "../../redux/actions"; |
|
|
|
import _ from "lodash"; |
|
|
|
import _ from "lodash"; |
|
|
|
import Drawer from "../Drawer"; |
|
|
|
import Drawer from "../Drawer"; |
|
|
|
import Search from "../Search"; |
|
|
|
import Search from "../Search"; |
|
|
|
|
|
|
|
import SearchResult from "./SearchResult"; |
|
|
|
//assets
|
|
|
|
//assets
|
|
|
|
import cartIcon from "./cart-blue.svg"; |
|
|
|
import cartIcon from "./cart-blue.svg"; |
|
|
|
// import whiteCartIcon from "./white-cart-icon.svg";
|
|
|
|
// import whiteCartIcon from "./white-cart-icon.svg";
|
|
|
@ -31,6 +32,8 @@ import dotsMenuLightIcon from "../../assets/icons/dots-menu-light.svg"; |
|
|
|
import bookmarkDeactiveLightIcon from "../../assets/icons/bookmark-deactive-light.svg"; |
|
|
|
import bookmarkDeactiveLightIcon from "../../assets/icons/bookmark-deactive-light.svg"; |
|
|
|
|
|
|
|
|
|
|
|
function Navbar({ |
|
|
|
function Navbar({ |
|
|
|
|
|
|
|
getCartProducts, |
|
|
|
|
|
|
|
cartProductsLength, |
|
|
|
pages, |
|
|
|
pages, |
|
|
|
isDark, |
|
|
|
isDark, |
|
|
|
isMobile, |
|
|
|
isMobile, |
|
|
@ -50,12 +53,12 @@ function Navbar({ |
|
|
|
headerOptions; |
|
|
|
headerOptions; |
|
|
|
|
|
|
|
|
|
|
|
const [top, setTop] = useState(false); |
|
|
|
const [top, setTop] = useState(false); |
|
|
|
|
|
|
|
const [search, setSearch] = useState(null); |
|
|
|
const [drawerOpen, setDrawerOpen] = useState(false); |
|
|
|
const [drawerOpen, setDrawerOpen] = useState(false); |
|
|
|
const [desktopMiddleFix, setDesktopMiddleFix] = useState(false); |
|
|
|
const [desktopMiddleFix, setDesktopMiddleFix] = useState(false); |
|
|
|
const [desktopEndTransform, setDesktopEndTransform] = useState(false); |
|
|
|
const [desktopEndTransform, setDesktopEndTransform] = useState(false); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
var lastScroll = window.scrollY; |
|
|
|
|
|
|
|
if (window.scrollY === 0) { |
|
|
|
if (window.scrollY === 0) { |
|
|
|
setTop(() => true); |
|
|
|
setTop(() => true); |
|
|
|
} |
|
|
|
} |
|
|
@ -68,25 +71,13 @@ function Navbar({ |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!isMobile) { |
|
|
|
|
|
|
|
window.addEventListener("scroll", () => { |
|
|
|
|
|
|
|
if (window.scrollY >= 64) { |
|
|
|
|
|
|
|
setDesktopMiddleFix(() => true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setDesktopMiddleFix(() => false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (window.scrollY > lastScroll && window.scrollY >= 90) { |
|
|
|
|
|
|
|
setDesktopEndTransform(() => true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setDesktopEndTransform(() => false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
lastScroll = window.scrollY; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if (!isMobile && isLogin) { |
|
|
|
|
|
|
|
getCartProducts(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [isLogin]); |
|
|
|
return isMobile ? ( |
|
|
|
return isMobile ? ( |
|
|
|
<div |
|
|
|
<div |
|
|
|
className={_.join( |
|
|
|
className={_.join( |
|
|
@ -241,7 +232,7 @@ function Navbar({ |
|
|
|
<Link to="/" className="flex flex-row items-center"> |
|
|
|
<Link to="/" className="flex flex-row items-center"> |
|
|
|
<img src={logoIcon} className="w-6" /> |
|
|
|
<img src={logoIcon} className="w-6" /> |
|
|
|
<span |
|
|
|
<span |
|
|
|
className={`text-base font-bold text-3xl text-blue52 transform translate-y-1 mr-2`} |
|
|
|
className={`font-bold text-3xl text-blue52 transform translate-y-1 mr-2`} |
|
|
|
> |
|
|
|
> |
|
|
|
دانوین |
|
|
|
دانوین |
|
|
|
</span> |
|
|
|
</span> |
|
|
@ -252,20 +243,25 @@ function Navbar({ |
|
|
|
style={{ maxWidth: "calc(100vw / 2)" }} |
|
|
|
style={{ maxWidth: "calc(100vw / 2)" }} |
|
|
|
></div> |
|
|
|
></div> |
|
|
|
<div |
|
|
|
<div |
|
|
|
className="flex w-full absolute left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2" |
|
|
|
className="flex flex-col w-full absolute left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2" |
|
|
|
style={{ maxWidth: "calc(100vw / 3)" }} |
|
|
|
style={{ maxWidth: "calc(100vw / 3)" }} |
|
|
|
> |
|
|
|
> |
|
|
|
<Search /> |
|
|
|
<Search onChange={(val) => setSearch(val)} /> |
|
|
|
|
|
|
|
{search && <SearchResult text={search} setText={setSearch} />} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
{isLogin && ( |
|
|
|
<div className="flex justify-end items-center gap-4"> |
|
|
|
<div className="flex justify-end items-center gap-4"> |
|
|
|
<Link to="/cart"> |
|
|
|
<Link to="/cart" className="relative"> |
|
|
|
<img src={cartIcon} alt="" className="w-9" /> |
|
|
|
<img src={cartIcon} alt="" className="w-11" /> |
|
|
|
|
|
|
|
<span className="absolute -right-2 -top-0.5 w-6 h-6 flex justify-center items-center bg-blue-500 bg-opacity-90 rounded-full text-white text-tiny"> |
|
|
|
|
|
|
|
{cartProductsLength} |
|
|
|
|
|
|
|
</span> |
|
|
|
</Link> |
|
|
|
</Link> |
|
|
|
{/* <img src={whiteCartIcon} alt="" className="w-5 h-5 ml-2" /> */} |
|
|
|
{/* <img src={whiteCartIcon} alt="" className="w-5 h-5 ml-2" /> */} |
|
|
|
{/* <img src={searchIcon} alt="" className="w-5 h-5 ml-2" /> */} |
|
|
|
{/* <img src={searchIcon} alt="" className="w-5 h-5 ml-2" /> */} |
|
|
|
{/* <img src={profileIcon} alt="" className="w-5 h-5" /> */} |
|
|
|
{/* <img src={profileIcon} alt="" className="w-5 h-5" /> */} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
)} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<div |
|
|
|
<div |
|
|
@ -286,9 +282,7 @@ function Navbar({ |
|
|
|
/> |
|
|
|
/> |
|
|
|
{/* <img src={whiteHamburgerMenu} alt="" className="w-3 h-3" /> */} |
|
|
|
{/* <img src={whiteHamburgerMenu} alt="" className="w-3 h-3" /> */} |
|
|
|
<span className={`text-sm text-blue52 ${productCategoryTextColor}`}> |
|
|
|
<span className={`text-sm text-blue52 ${productCategoryTextColor}`}> |
|
|
|
دسته بندی کالاها |
|
|
|
دسته بندی کالاها |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div |
|
|
|
<div |
|
|
@ -326,10 +320,14 @@ const mapStateToProps = (state) => ({ |
|
|
|
isMobile: state.publicApi.isMobile, |
|
|
|
isMobile: state.publicApi.isMobile, |
|
|
|
headerOptions: state.publicApi.headerOptions, |
|
|
|
headerOptions: state.publicApi.headerOptions, |
|
|
|
isLogin: state.user.status, |
|
|
|
isLogin: state.user.status, |
|
|
|
|
|
|
|
cartProductsLength: state.userProduct.list?.length, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = { |
|
|
|
|
|
|
|
getCartProducts: userProduct.list, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(Navbar); |
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Navbar); |
|
|
|
|
|
|
|
|
|
|
|
Navbar.defaultProps = { |
|
|
|
Navbar.defaultProps = { |
|
|
|
pages: [ |
|
|
|
pages: [ |
|
|
|