diff --git a/app/src/components/Base.tsx b/app/src/components/Base.tsx index cbce34e..19641a7 100644 --- a/app/src/components/Base.tsx +++ b/app/src/components/Base.tsx @@ -1,4 +1,4 @@ -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import i18n from "i18next"; import { useTranslation } from "react-i18next"; import { @@ -6,12 +6,27 @@ import { Paper, BottomNavigation, BottomNavigationAction, + List, + ListItemIcon, + ListItemButton, + ListItemText, + IconButton, + Drawer, + useMediaQuery, + Theme, + useTheme, } from "@mui/material"; -import { Home, Info, CorporateFare, QuestionAnswer } from "@mui/icons-material"; +import { + Home, + Info, + CorporateFare, + QuestionAnswer, + Menu, +} from "@mui/icons-material"; import { Link, Outlet, useLocation, useParams } from "react-router-dom"; import { getLocaleOrFallback, SAVED_LOCALE } from "../locale"; -const ROUTES = ["home", "about", "organization", "faq"] as const; +const ROUTE_NAMES = ["home", "about", "organization", "faq"] as const; const ICONS = { home: Home, @@ -20,19 +35,35 @@ const ICONS = { faq: QuestionAnswer, } as const; -const ROUTE_NAME_TO_ROUTE = { +const ROUTE_NAME_TO_PATH = { home: "", about: "about", organization: "organization", faq: "faq", } as const; +type RouteName = (typeof ROUTE_NAMES)[number]; +type NavigationIcon = (typeof ICONS)[keyof typeof ICONS]; +type Path = (typeof ROUTE_NAME_TO_PATH)[keyof typeof ROUTE_NAME_TO_PATH]; +type PathWithLocale = `${ReturnType}/${Path}`; + +type NavigationBarItem = { + routeName: RouteName; + Icon: NavigationIcon; + path: Path; + pathWithLocale: PathWithLocale; +}; + export const Base = () => { const { t } = useTranslation(); const { pathname } = useLocation(); const pathWithoutLocale = pathname.split("/").at(-1); const params = useParams(); const locale = getLocaleOrFallback(params.locale as string); + const theme = useTheme(); + const isSmall = useMediaQuery((theme) => theme.breakpoints.down("sm")); + + const [isDrawerOpen, setIsDrawerOpen] = useState(false); useEffect(() => { localStorage.setItem(SAVED_LOCALE, locale); @@ -43,7 +74,64 @@ export const Base = () => { window.scrollTo(0, 0); }, [pathWithoutLocale]); - return ( + const navigationBarItems: NavigationBarItem[] = ROUTE_NAMES.map( + (routeName) => { + const path = ROUTE_NAME_TO_PATH[routeName]; + + return { + routeName, + Icon: ICONS[routeName], + path, + pathWithLocale: `${locale}/${path}`, + }; + }, + ); + + return isSmall ? ( + + + setIsDrawerOpen(true)}> + + + + setIsDrawerOpen(false)} + > + + {navigationBarItems.map( + ({ routeName, Icon, path, pathWithLocale }) => { + const color = + pathWithoutLocale === path + ? theme.palette.primary.main + : undefined; + + return ( + setIsDrawerOpen(false)} + > + + + + + + ); + }, + )} + + + + + + + ) : ( @@ -53,22 +141,18 @@ export const Base = () => { elevation={2} > - {ROUTES.map((r) => { - const Icon = ICONS[r]; - const route = ROUTE_NAME_TO_ROUTE[r]; - const routeWithLocale = `${locale}/${route}`; - - return ( + {navigationBarItems.map( + ({ routeName, Icon, path, pathWithLocale }) => ( } - to={routeWithLocale} - value={route} + key={routeName} + label={t(`routes.${routeName}`)} component={Link} + to={pathWithLocale} + icon={} + value={path} /> - ); - })} + ), + )}