Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
Use screen width from store rather than hook
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiggr committed Nov 5, 2021
1 parent 90b38c4 commit b15911d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 35 deletions.
15 changes: 8 additions & 7 deletions src/components/theme/Header/HeaderNavigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useWindowSize from '../../../helpers/useWindowSize';
import downIcon from '@plone/volto/icons/down-key.svg';
import closeIcon from '@plone/volto/icons/clear.svg';
import { Icon } from '@plone/volto/components';
import { connect } from 'react-redux';

const MobileNav = ({ items, activeItem }) => {
const [expanded, setExpanded] = React.useState(false);
Expand Down Expand Up @@ -61,28 +62,26 @@ const MobileNav = ({ items, activeItem }) => {
);
};

const HeaderNavigation = ({ items }) => {
const HeaderNavigation = ({ items, pageWidth }) => {
const [activeItem, setActiveItem] = React.useState('');
const [isMobile, setIsMobile] = React.useState(false);
const history = useHistory();
const size = useWindowSize();

React.useEffect(() => {
const { width } = size;
const activeRouteDetected = items.filter(
(item) => item.url === history.location.pathname,
);
if (activeRouteDetected && activeRouteDetected.length > 0) {
setActiveItem(activeRouteDetected[0]);
}
if (width && width <= 768) {
if (pageWidth && pageWidth <= 768) {
setIsMobile(true);
}
if (width && width > 768) {
if (pageWidth && pageWidth > 768) {
setIsMobile(false);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [items, size]);
}, [items, pageWidth]);

return (
<React.Fragment>
Expand All @@ -108,4 +107,6 @@ const HeaderNavigation = ({ items }) => {
);
};

export default HeaderNavigation;
export default connect((state) => ({
pageWidth: state.screen.page.width,
}))(HeaderNavigation);
28 changes: 0 additions & 28 deletions src/helpers/useWindowSize.jsx

This file was deleted.

0 comments on commit b15911d

Please sign in to comment.