Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
fix: page url changes close mobile menu
Browse files Browse the repository at this point in the history
  • Loading branch information
tabathadelane committed Jun 30, 2022
1 parent 6862958 commit 6e6ff42
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/@newrelic/gatsby-theme-newrelic/components/GlobalHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import Button from '@newrelic/gatsby-theme-newrelic/src/components/Button';
import GlobalNavLink from '@newrelic/gatsby-theme-newrelic/src/components/GlobalNavLink';
import useMedia from 'use-media';
import useThemeTranslation from '@newrelic/gatsby-theme-newrelic/src/hooks/useThemeTranslation';
import { useInstrumentedHandler } from '@newrelic/gatsby-theme-newrelic';
import {
useInstrumentedHandler,
usePrevious,
} from '@newrelic/gatsby-theme-newrelic';
import { Menu, X } from 'react-feather';
import { useLocation } from '@reach/router';
import NewLogo from './NewLogo';
Expand Down Expand Up @@ -75,6 +78,12 @@ const MOBILE_BREAKPOINT = '600px';

const GlobalHeader = ({ className, activeSite }) => {
const { t } = useThemeTranslation();
const hideLogoText = useMedia({ maxWidth: '350px' });
const location = useLocation();
const previousLocation = usePrevious(location);
const hasChangedPage = location.pathname !== previousLocation?.pathname;
const UserIsInMainPage = location.pathname === '/instant-observability/';
const showGetStarted = !!UserIsInMainPage;
const [isOpen, setOpen] = React.useState(false);

React.useEffect(() => {
Expand All @@ -85,10 +94,11 @@ const GlobalHeader = ({ className, activeSite }) => {
}
}, [isOpen]);

const hideLogoText = useMedia({ maxWidth: '350px' });
const location = useLocation();
const UserIsInMainPage = location.pathname === '/instant-observability/';
const showGetStarted = !!UserIsInMainPage;
React.useEffect(() => {
if (isOpen && hasChangedPage) {
setOpen(!isOpen);
}
}, [hasChangedPage, setOpen, isOpen]);

return (
<>
Expand Down

0 comments on commit 6e6ff42

Please sign in to comment.