Skip to content

Commit 1bbda77

Browse files
committed
Use compact mobile section menu for competition nav
1 parent d9576cd commit 1bbda77

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

src/layouts/CompetitionLayout/CompetitionLayout.tsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from 'classnames';
2-
import { useEffect, useRef } from 'react';
2+
import { useEffect, useMemo, useRef, useState } from 'react';
33
import { ErrorBoundary } from 'react-error-boundary';
44
import { Outlet, useLocation, useParams } from 'react-router-dom';
55
import { BarLoader } from 'react-spinners';
@@ -17,6 +17,7 @@ export function CompetitionLayout() {
1717
const { pathname } = useLocation();
1818

1919
const ref = useRef<HTMLDivElement>(null);
20+
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
2021

2122
const { data: wcif, dataUpdatedAt, isFetching } = useWcif(competitionId!);
2223

@@ -25,14 +26,45 @@ export function CompetitionLayout() {
2526
wcif: wcif,
2627
});
2728

29+
const currentTab = useMemo(
30+
() =>
31+
tabs.find((tab) => pathname === tab.href) ||
32+
tabs.find((tab) => pathname.startsWith(tab.href)),
33+
[tabs, pathname],
34+
);
35+
2836
useEffect(() => {
2937
ref.current?.scrollTo(0, 0);
38+
setIsMobileMenuOpen(false);
3039
}, [pathname]);
3140

3241
const Header = (
3342
<nav className="z-10 flex justify-center w-full shadow-md shadow-tertiary-dark print:hidden bg-panel">
3443
<Container className="justify-between md:flex-row">
35-
<div className="flex">
44+
<div className="flex w-full flex-col space-y-2 p-2 md:hidden">
45+
<button
46+
aria-expanded={isMobileMenuOpen}
47+
className="flex w-full items-center justify-between rounded-md border border-tertiary-weak bg-panel px-2 py-2"
48+
onClick={() => {
49+
setIsMobileMenuOpen((prev) => !prev);
50+
}}
51+
type="button">
52+
<span className="type-meta text-muted">Section</span>
53+
<span className="type-body text-primary">
54+
{currentTab?.text || tabs[0]?.text || 'Menu'}
55+
</span>
56+
</button>
57+
{isMobileMenuOpen && (
58+
<div className="grid grid-cols-2 gap-2">
59+
{tabs
60+
.filter((tab) => !tab.hiddenOnMobile)
61+
.map((i) => (
62+
<StyledNavLink key={i.href} className="type-body-sm" to={i.href} text={i.text} />
63+
))}
64+
</div>
65+
)}
66+
</div>
67+
<div className="hidden w-full p-2 md:flex">
3668
{tabs.map((i) => (
3769
<StyledNavLink
3870
key={i.href}

0 commit comments

Comments
 (0)