|
|
|
@@ -1,4 +1,4 @@ |
|
|
|
import React, { useState, useMemo } from "react"; |
|
|
|
import React, { useState, useMemo, useEffect, useRef } from "react"; |
|
|
|
import { |
|
|
|
AddOfferButton, |
|
|
|
DrawerContainer, |
|
|
|
@@ -34,12 +34,17 @@ import selectedTheme from "../../themes"; |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
import { IconButton } from "../Buttons/IconButton/IconButton"; |
|
|
|
import { Icon } from "../Icon/Icon"; |
|
|
|
import { useSelector } from "react-redux"; |
|
|
|
import { selectJWTToken } from "../../store/selectors/loginSelectors"; |
|
|
|
|
|
|
|
const Header = () => { |
|
|
|
const [openDrawer, setOpenDrawer] = useState(false); |
|
|
|
const { t } = useTranslation(); |
|
|
|
const theme = useTheme(); |
|
|
|
const searchRef = useRef(null); |
|
|
|
const matches = useMediaQuery(theme.breakpoints.down("md")); |
|
|
|
const user = useSelector(selectJWTToken); |
|
|
|
|
|
|
|
|
|
|
|
const handleToggleDrawer = () => { |
|
|
|
setOpenDrawer(!openDrawer); |
|
|
|
@@ -54,6 +59,41 @@ const Header = () => { |
|
|
|
const [userPopoverOpen, setUserPopoverOpen] = useState(false); |
|
|
|
const [userAnchorEl, setUserAnchorEl] = useState(null); |
|
|
|
|
|
|
|
const [shouldShow, setShouldShow] = useState(true); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
let shouldShowHeader = true; |
|
|
|
if ( |
|
|
|
location.pathname === "/login" || |
|
|
|
location.pathname === "/register" || |
|
|
|
location.pathname === "/forgot-password" || |
|
|
|
location.pathname === "/reset-password" |
|
|
|
) { |
|
|
|
shouldShowHeader = false; |
|
|
|
} |
|
|
|
console.log(user); |
|
|
|
if (location.pathname === "/" && user.JwtToken?.length === 0) { |
|
|
|
shouldShowHeader = false; |
|
|
|
} |
|
|
|
setShouldShow(shouldShowHeader); |
|
|
|
}, [location, user]); |
|
|
|
|
|
|
|
// let listener; |
|
|
|
const handleFocusSearch = () => { |
|
|
|
// console.log('focus'); |
|
|
|
// listener = (event) => { |
|
|
|
// if (event.keyCode === 13) { |
|
|
|
// event.preventDefault(); |
|
|
|
// console.log('detektovano'); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// searchRef.current.addEventListener('keyup', listener); |
|
|
|
} |
|
|
|
const handleBlurSearch = () => { |
|
|
|
// console.log('blur'); |
|
|
|
// searchRef.current.removeEventListener('keyup', listener); |
|
|
|
} |
|
|
|
|
|
|
|
const drawerContent = useMemo( |
|
|
|
() => ( |
|
|
|
<DrawerContainer> |
|
|
|
@@ -112,6 +152,7 @@ const Header = () => { |
|
|
|
elevation={0} |
|
|
|
positionFixed |
|
|
|
sx={{ backgroundColor: "white"}} |
|
|
|
style={{display: shouldShow ? "flex" : "none"}} |
|
|
|
> |
|
|
|
<Toolbar> |
|
|
|
<ToolsContainer> |
|
|
|
@@ -135,6 +176,9 @@ const Header = () => { |
|
|
|
), |
|
|
|
}} |
|
|
|
label={t("header.searchOffers")} |
|
|
|
onFocus={handleFocusSearch} |
|
|
|
onBlur={handleBlurSearch} |
|
|
|
ref={searchRef} |
|
|
|
/> |
|
|
|
<ToolsButtonsContainer mobile={matches}> |
|
|
|
{matches ? ( |