|
|
|
@@ -44,6 +44,7 @@ import { toggleCreateOfferModal } from "../../store/actions/modal/modalActions"; |
|
|
|
import { ReactComponent as Marketplace } from "../../assets/images/svg/package.svg"; |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
import useIsTablet from "../../hooks/useIsTablet"; |
|
|
|
import { clearFilters } from "../../store/actions/filters/filtersActions"; |
|
|
|
|
|
|
|
const Header = () => { |
|
|
|
const theme = useTheme(); |
|
|
|
@@ -58,6 +59,7 @@ const Header = () => { |
|
|
|
const [shouldShow, setShouldShow] = useState(true); |
|
|
|
const routeMatch = useRouteMatch(); |
|
|
|
const { isTablet } = useIsTablet(); |
|
|
|
const [logoClicked, setLogoClicked] = useState(false); |
|
|
|
const { t } = useTranslation(); |
|
|
|
|
|
|
|
// Dont show header on auth routes(login, register, etc.) and admin routes |
|
|
|
@@ -73,6 +75,37 @@ const Header = () => { |
|
|
|
} |
|
|
|
}, []); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (logoClicked) { |
|
|
|
if (isAdminRoute()) { |
|
|
|
history.push({ |
|
|
|
pathname: ADMIN_HOME_PAGE, |
|
|
|
state: { |
|
|
|
logo: true, |
|
|
|
}, |
|
|
|
}); |
|
|
|
} else { |
|
|
|
if (user) { |
|
|
|
history.push({ |
|
|
|
pathname: HOME_PAGE, |
|
|
|
state: { |
|
|
|
logo: true, |
|
|
|
}, |
|
|
|
}); |
|
|
|
} else { |
|
|
|
history.push({ |
|
|
|
pathname: MARKETPLACE_PAGE, |
|
|
|
state: { |
|
|
|
logo: true, |
|
|
|
}, |
|
|
|
}); |
|
|
|
} |
|
|
|
if (searchRef?.current) searchRef.current.value = ""; |
|
|
|
} |
|
|
|
setLogoClicked(false); |
|
|
|
} |
|
|
|
}, [logoClicked]); |
|
|
|
|
|
|
|
// Sets value into search input based on query string |
|
|
|
useEffect(() => { |
|
|
|
if (searchRef.current) { |
|
|
|
@@ -99,30 +132,15 @@ const Header = () => { |
|
|
|
|
|
|
|
// When user clicks logo, he sends specific state so filters can be removed |
|
|
|
const handleLogoClick = () => { |
|
|
|
if (isAdminRoute()) { |
|
|
|
history.push({ |
|
|
|
pathname: ADMIN_HOME_PAGE, |
|
|
|
state: { |
|
|
|
logo: true, |
|
|
|
}, |
|
|
|
}); |
|
|
|
} else { |
|
|
|
if (user) { |
|
|
|
history.push({ |
|
|
|
pathname: HOME_PAGE, |
|
|
|
state: { |
|
|
|
logo: true, |
|
|
|
}, |
|
|
|
}); |
|
|
|
} else { |
|
|
|
history.push({ |
|
|
|
pathname: MARKETPLACE_PAGE, |
|
|
|
state: { |
|
|
|
logo: true, |
|
|
|
}, |
|
|
|
}); |
|
|
|
} |
|
|
|
if (searchRef?.current) searchRef.current.value = ""; |
|
|
|
if ( |
|
|
|
!( |
|
|
|
routeMatches(HOME_PAGE) || |
|
|
|
routeMatches(BASE_PAGE) || |
|
|
|
routeMatches(MARKETPLACE_PAGE) |
|
|
|
) |
|
|
|
) { |
|
|
|
dispatch(clearFilters()); |
|
|
|
setLogoClicked(true); |
|
|
|
} |
|
|
|
}; |
|
|
|
|