|
|
|
@ -1,10 +1,11 @@ |
|
|
|
|
import React, { useEffect, useState } from "react"; |
|
|
|
|
import { Link, useNavigate } from "react-router-dom"; |
|
|
|
|
import { connect } from "react-redux"; |
|
|
|
|
import {publicApi} from "../../redux/actions"; |
|
|
|
|
import { userProduct } from "../../redux/actions"; |
|
|
|
|
import _ from "lodash"; |
|
|
|
|
import Drawer from "../Drawer"; |
|
|
|
|
import Search from "../Search"; |
|
|
|
|
import SearchResult from "./SearchResult"; |
|
|
|
|
//assets
|
|
|
|
|
import cartIcon from "./cart-blue.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"; |
|
|
|
|
|
|
|
|
|
function Navbar({ |
|
|
|
|
getCartProducts, |
|
|
|
|
cartProductsLength, |
|
|
|
|
pages, |
|
|
|
|
isDark, |
|
|
|
|
isMobile, |
|
|
|
@ -50,12 +53,12 @@ function Navbar({ |
|
|
|
|
headerOptions; |
|
|
|
|
|
|
|
|
|
const [top, setTop] = useState(false); |
|
|
|
|
const [search, setSearch] = useState(null); |
|
|
|
|
const [drawerOpen, setDrawerOpen] = useState(false); |
|
|
|
|
const [desktopMiddleFix, setDesktopMiddleFix] = useState(false); |
|
|
|
|
const [desktopEndTransform, setDesktopEndTransform] = useState(false); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
var lastScroll = window.scrollY; |
|
|
|
|
if (window.scrollY === 0) { |
|
|
|
|
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 ? ( |
|
|
|
|
<div |
|
|
|
|
className={_.join( |
|
|
|
@ -241,7 +232,7 @@ function Navbar({ |
|
|
|
|
<Link to="/" className="flex flex-row items-center"> |
|
|
|
|
<img src={logoIcon} className="w-6" /> |
|
|
|
|
<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> |
|
|
|
@ -252,20 +243,25 @@ function Navbar({ |
|
|
|
|
style={{ maxWidth: "calc(100vw / 2)" }} |
|
|
|
|
></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)" }} |
|
|
|
|
> |
|
|
|
|
<Search /> |
|
|
|
|
<Search onChange={(val) => setSearch(val)} /> |
|
|
|
|
{search && <SearchResult text={search} setText={setSearch} />} |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
{isLogin && ( |
|
|
|
|
<div className="flex justify-end items-center gap-4"> |
|
|
|
|
<Link to="/cart"> |
|
|
|
|
<img src={cartIcon} alt="" className="w-9" /> |
|
|
|
|
<Link to="/cart" className="relative"> |
|
|
|
|
<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> |
|
|
|
|
{/* <img src={whiteCartIcon} 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" /> */} |
|
|
|
|
</div> |
|
|
|
|
)} |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<div |
|
|
|
@ -286,9 +282,7 @@ function Navbar({ |
|
|
|
|
/> |
|
|
|
|
{/* <img src={whiteHamburgerMenu} alt="" className="w-3 h-3" /> */} |
|
|
|
|
<span className={`text-sm text-blue52 ${productCategoryTextColor}`}> |
|
|
|
|
دسته بندی کالاها |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
دسته بندی کالاها |
|
|
|
|
</span> |
|
|
|
|
</div> |
|
|
|
|
<div |
|
|
|
@ -326,10 +320,14 @@ const mapStateToProps = (state) => ({ |
|
|
|
|
isMobile: state.publicApi.isMobile, |
|
|
|
|
headerOptions: state.publicApi.headerOptions, |
|
|
|
|
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 = { |
|
|
|
|
pages: [ |
|
|
|
|