|
|
@ -9,6 +9,7 @@ import _ from "lodash"; |
|
|
|
import Drawer from "../Drawer"; |
|
|
|
import Drawer from "../Drawer"; |
|
|
|
import Search from "../Search"; |
|
|
|
import Search from "../Search"; |
|
|
|
import SearchResult from "./SearchResult"; |
|
|
|
import SearchResult from "./SearchResult"; |
|
|
|
|
|
|
|
import Loading from "../Loading"; |
|
|
|
|
|
|
|
|
|
|
|
//assets
|
|
|
|
//assets
|
|
|
|
import cartIcon from "./cart-blue.svg"; |
|
|
|
import cartIcon from "./cart-blue.svg"; |
|
|
@ -24,18 +25,24 @@ import arrowBlueIcon from "../../assets/icons/arrow-right-blue.svg"; |
|
|
|
import arrowWhiteIcon from "../../assets/icons/arrow-left-white.svg"; |
|
|
|
import arrowWhiteIcon from "../../assets/icons/arrow-left-white.svg"; |
|
|
|
import dotsMenuDarkIcon from "../../assets/icons/dots-menu-dark.svg"; |
|
|
|
import dotsMenuDarkIcon from "../../assets/icons/dots-menu-dark.svg"; |
|
|
|
import bookmarkDeactiveDarkIcon from "../../assets/icons/bookmark-deactive-dark.svg"; |
|
|
|
import bookmarkDeactiveDarkIcon from "../../assets/icons/bookmark-deactive-dark.svg"; |
|
|
|
|
|
|
|
import bookmarkActiveDarkIcon from "../../assets/icons/bookmark-active-dark.svg"; |
|
|
|
import dotsMenuLightIcon from "../../assets/icons/dots-menu-light.svg"; |
|
|
|
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"; |
|
|
|
|
|
|
|
import bookmarkActiveLightIcon from "../../assets/icons/bookmark-active-light.svg"; |
|
|
|
|
|
|
|
|
|
|
|
function Navbar({ |
|
|
|
function Navbar({ |
|
|
|
getCartProducts, |
|
|
|
getCartProducts, |
|
|
|
|
|
|
|
getUserFavorite, |
|
|
|
cartProductsLength, |
|
|
|
cartProductsLength, |
|
|
|
pages, |
|
|
|
pages, |
|
|
|
isDark, |
|
|
|
isDark, |
|
|
|
isMobile, |
|
|
|
isMobile, |
|
|
|
isLogin, |
|
|
|
user, |
|
|
|
headerOptions, |
|
|
|
headerOptions, |
|
|
|
addToFavorite, |
|
|
|
addToFavorite, |
|
|
|
|
|
|
|
deleteBookmark, |
|
|
|
|
|
|
|
bookmarkLoading, |
|
|
|
|
|
|
|
userFavoriteList, |
|
|
|
language, |
|
|
|
language, |
|
|
|
}) { |
|
|
|
}) { |
|
|
|
const navigation = useNavigate(); |
|
|
|
const navigation = useNavigate(); |
|
|
@ -46,11 +53,22 @@ function Navbar({ |
|
|
|
const [search, setSearch] = useState(null); |
|
|
|
const [search, setSearch] = useState(null); |
|
|
|
const [drawerOpen, setDrawerOpen] = useState(false); |
|
|
|
const [drawerOpen, setDrawerOpen] = useState(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isActiveBookmark = React.useMemo(() => { |
|
|
|
|
|
|
|
return userFavoriteList?.find((object) => |
|
|
|
|
|
|
|
headerOptions?.productId |
|
|
|
|
|
|
|
? object?.productId === headerOptions?.productId |
|
|
|
|
|
|
|
: object?.contentId === headerOptions?.contentId |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, [headerOptions, userFavoriteList]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(Boolean(isActiveBookmark)); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (window.scrollY === 0) { |
|
|
|
if (window.scrollY === 0) { |
|
|
|
setTop(() => true); |
|
|
|
setTop(() => true); |
|
|
|
} |
|
|
|
} |
|
|
|
if (isMobile) { |
|
|
|
if (isMobile) { |
|
|
|
|
|
|
|
// getUserFavorite();
|
|
|
|
window.addEventListener("scroll", () => { |
|
|
|
window.addEventListener("scroll", () => { |
|
|
|
if (window.scrollY === 0) { |
|
|
|
if (window.scrollY === 0) { |
|
|
|
setTop(() => true); |
|
|
|
setTop(() => true); |
|
|
@ -62,13 +80,11 @@ function Navbar({ |
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (!isMobile && isLogin) { |
|
|
|
if (!isMobile && user) { |
|
|
|
console.log(111); |
|
|
|
|
|
|
|
// console.log/("gl3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getCartProducts(); |
|
|
|
getCartProducts(); |
|
|
|
} |
|
|
|
} |
|
|
|
}, [isLogin]); |
|
|
|
}, [user]); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div |
|
|
|
<div |
|
|
@ -77,7 +93,9 @@ function Navbar({ |
|
|
|
backgroundColor: !top ? (isDark ? "#061B30" : "white") : "", |
|
|
|
backgroundColor: !top ? (isDark ? "#061B30" : "white") : "", |
|
|
|
}} |
|
|
|
}} |
|
|
|
> |
|
|
|
> |
|
|
|
<div className="w-full lg:w-11/12 lg:mx-auto relative flex items-center justify-between py-3 px-4 bg-white"> |
|
|
|
<div className="w-full lg:w-11/12 lg:mx-auto relative flex items-center justify-between py-3 px-4" style={{ |
|
|
|
|
|
|
|
backgroundColor: isDark ? "#061B30" : "white" |
|
|
|
|
|
|
|
}}> |
|
|
|
{/* desktop */} |
|
|
|
{/* desktop */} |
|
|
|
<div className=" items-center hidden lg:flex"> |
|
|
|
<div className=" items-center hidden lg:flex"> |
|
|
|
<Link |
|
|
|
<Link |
|
|
@ -193,7 +211,25 @@ function Navbar({ |
|
|
|
</Link> |
|
|
|
</Link> |
|
|
|
</> |
|
|
|
</> |
|
|
|
)} |
|
|
|
)} |
|
|
|
{bookmark && ( |
|
|
|
{bookmark ? ( |
|
|
|
|
|
|
|
bookmarkLoading ? ( |
|
|
|
|
|
|
|
<Loading size={2} color="bg-green-500" /> |
|
|
|
|
|
|
|
) : isActiveBookmark ? ( |
|
|
|
|
|
|
|
<img |
|
|
|
|
|
|
|
src={ |
|
|
|
|
|
|
|
isDark ? bookmarkActiveDarkIcon : bookmarkActiveLightIcon |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
alt="bookmark" |
|
|
|
|
|
|
|
className="w-7 flex lg:hidden" |
|
|
|
|
|
|
|
onClick={() => |
|
|
|
|
|
|
|
deleteBookmark({ |
|
|
|
|
|
|
|
id: userFavoriteList?.find( |
|
|
|
|
|
|
|
(object) => object?.productId === headerOptions?.productId |
|
|
|
|
|
|
|
)?.id, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
) : ( |
|
|
|
<img |
|
|
|
<img |
|
|
|
src={ |
|
|
|
src={ |
|
|
|
isDark ? bookmarkDeactiveDarkIcon : bookmarkDeactiveLightIcon |
|
|
|
isDark ? bookmarkDeactiveDarkIcon : bookmarkDeactiveLightIcon |
|
|
@ -202,7 +238,8 @@ function Navbar({ |
|
|
|
className="w-7 flex lg:hidden" |
|
|
|
className="w-7 flex lg:hidden" |
|
|
|
onClick={() => addToFavorite({ [bookmark]: location.getId() })} |
|
|
|
onClick={() => addToFavorite({ [bookmark]: location.getId() })} |
|
|
|
/> |
|
|
|
/> |
|
|
|
)} |
|
|
|
) |
|
|
|
|
|
|
|
) : null} |
|
|
|
{menu && ( |
|
|
|
{menu && ( |
|
|
|
<img |
|
|
|
<img |
|
|
|
src={isDark ? dotsMenuDarkIcon : dotsMenuLightIcon} |
|
|
|
src={isDark ? dotsMenuDarkIcon : dotsMenuLightIcon} |
|
|
@ -242,7 +279,7 @@ function Navbar({ |
|
|
|
onClick={() => setOverLayer(true)} |
|
|
|
onClick={() => setOverLayer(true)} |
|
|
|
/> |
|
|
|
/> |
|
|
|
|
|
|
|
|
|
|
|
{isLogin && ( |
|
|
|
{user && ( |
|
|
|
<div className="hidden lg:flex justify-end items-center gap-4"> |
|
|
|
<div className="hidden lg:flex justify-end items-center gap-4"> |
|
|
|
<Link to="/cart" className="relative"> |
|
|
|
<Link to="/cart" className="relative"> |
|
|
|
<img src={cartIcon} alt="" className="w-8" /> |
|
|
|
<img src={cartIcon} alt="" className="w-8" /> |
|
|
@ -256,7 +293,7 @@ function Navbar({ |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
)} |
|
|
|
)} |
|
|
|
|
|
|
|
|
|
|
|
{!isLogin ? ( |
|
|
|
{!user ? ( |
|
|
|
<Link |
|
|
|
<Link |
|
|
|
to="/signup" |
|
|
|
to="/signup" |
|
|
|
className="bg-blueC0 font-semibold text-white rounded-md px-4 py-3 text-sm mr-7 hover:bg-opacity-90 shadow-sm" |
|
|
|
className="bg-blueC0 font-semibold text-white rounded-md px-4 py-3 text-sm mr-7 hover:bg-opacity-90 shadow-sm" |
|
|
@ -284,15 +321,19 @@ const mapStateToProps = (state) => ({ |
|
|
|
isDark: state.publicApi.isDark, |
|
|
|
isDark: state.publicApi.isDark, |
|
|
|
isMobile: state.publicApi.isMobile, |
|
|
|
isMobile: state.publicApi.isMobile, |
|
|
|
headerOptions: state.publicApi.headerOptions, |
|
|
|
headerOptions: state.publicApi.headerOptions, |
|
|
|
isLogin: state.user.status, |
|
|
|
user: state.user.status, |
|
|
|
cartProductsLength: state.userProduct.list?.filter( |
|
|
|
cartProductsLength: state.userProduct.list?.filter( |
|
|
|
(product) => product.condition < 2 |
|
|
|
(product) => product.condition < 2 |
|
|
|
)?.length, |
|
|
|
)?.length, |
|
|
|
|
|
|
|
bookmarkLoading: state.userFavorite.loading, |
|
|
|
|
|
|
|
userFavoriteList: state.userFavorite.list, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = { |
|
|
|
const mapDispatchToProps = { |
|
|
|
getCartProducts: userProduct.list, |
|
|
|
getCartProducts: userProduct.list, |
|
|
|
addToFavorite: userFavorite.add, |
|
|
|
addToFavorite: userFavorite.add, |
|
|
|
|
|
|
|
deleteBookmark: userFavorite.del, |
|
|
|
|
|
|
|
getUserFavorite: userFavorite.list |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Navbar); |
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Navbar); |
|
|
|