Skip to content

Commit

Permalink
VKT(Frontend): Take MobileNavigationMenuWithPortal into use [deploy]
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoivisto committed Sep 30, 2024
1 parent e341bd0 commit fd3cc4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
41 changes: 15 additions & 26 deletions frontend/packages/vkt/src/components/layouts/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { AppBar, Toolbar } from '@mui/material';
import { TFunction } from 'i18next';
import { useState } from 'react';
import { Link, matchPath, useLocation } from 'react-router-dom';
import {
CookieBanner,
LangSelector,
MobileNavigationMenuContents,
MobileNavigationMenuToggle,
MobileNavigationMenuWithPortal,
NavigationLinks,
OPHClerkLogo,
OPHLogoViewer,
Expand Down Expand Up @@ -102,11 +100,7 @@ const PublicNavigationLinks = () => {
);
};

const PublicMobileNavigationMenu = ({
closeMenu,
}: {
closeMenu: () => void;
}) => {
const PublicMobileNavigationMenu = () => {
const translateCommon = useCommonTranslation();
const { pathname } = useLocation();
const { goodAndSatisfactoryLevel } = useAppSelector(featureFlagsSelector);
Expand All @@ -117,13 +111,23 @@ const PublicMobileNavigationMenu = ({
translateCommon,
);

const portalContainer = document.getElementById('mobile-menu-placeholder');

if (!portalContainer) {
return null;
}

return (
<MobileNavigationMenuContents
<MobileNavigationMenuWithPortal
navigationAriaLabel={translateCommon(
'header.accessibility.mainNavigation',
)}
openStateLabel="Sulje"
openStateAriaLabel="Sulje valikko"
closedStateLabel="Valikko"
closedStateAriaLabel="Avaa valikko"
links={navigationLinks}
closeMenu={closeMenu}
portalContainer={portalContainer}
/>
);
};
Expand Down Expand Up @@ -159,7 +163,6 @@ export const Header = (): JSX.Element => {
}
}
};
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);

useInterval(heartBeat, 5000); // Every 5 seconds

Expand Down Expand Up @@ -218,16 +221,7 @@ export const Header = (): JSX.Element => {
<div className="header__navigation">
{isAuthenticated && <ClerkNavTabs />}
{isPublicUrl && !isPhone && <PublicNavigationLinks />}
{isPublicUrl && isPhone && (
<MobileNavigationMenuToggle
openStateLabel="Sulje"
openStateAriaLabel="Sulje valikko"
closedStateLabel="Valikko"
closedStateAriaLabel="Avaa valikko"
isOpen={isMobileMenuOpen}
setIsOpen={setIsMobileMenuOpen}
/>
)}
{isPublicUrl && isPhone && <PublicMobileNavigationMenu />}
</div>
<div className="header__language-select">
{isAuthenticated && <ClerkHeaderButtons />}
Expand All @@ -243,11 +237,6 @@ export const Header = (): JSX.Element => {
)}
</div>
</Toolbar>
{isPhone && isMobileMenuOpen && (
<PublicMobileNavigationMenu
closeMenu={() => setIsMobileMenuOpen(false)}
/>
)}
</AppBar>
{!isClerkUI && (
<CookieBanner
Expand Down
3 changes: 2 additions & 1 deletion frontend/packages/vkt/src/routers/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export const AppRouter: FC = () => {
<Notifier />
<ScrollToTop />
<PersistGate persistor={persistor} />
<main className="content" id="main-content">
<main className="content rows" id="main-content">
<div id="mobile-menu-placeholder" className="rows" />
<div className="content__container">
<Outlet />
</div>
Expand Down

0 comments on commit fd3cc4e

Please sign in to comment.