import React, { useState, useEffect, createRef, useMemo, useRef } from "react"; import { Link } from "react-router-dom"; import { Container, Tabs, Tab, useMediaQuery, IconButton, SwipeableDrawer, Paper, ListItem, ListItemText, List, ListItemButton, Box, } from "@mui/material"; import { useTheme } from "@mui/material/styles"; import MenuIcon from "@mui/icons-material/Menu"; import MenuOpenIcon from "@mui/icons-material/MenuOpen"; import { useIntl } from "react-intl"; import LanguageSwitcher from "layouts/common/languageSwitcher"; import DarkModeToggle from "layouts/common/darkModeToggle"; const Navigation = () => { const theme = useTheme(); const t = useIntl(); const matches = useMediaQuery(theme.breakpoints.down("sm")); const iOS = typeof navigator !== "undefined" && /iPad|iPhone|iPod/.test(navigator.userAgent); const [value, setValue] = useState(1); const [openDrawer, setOpenDrawer] = useState(false); const tabsActions = useRef(null); const wrapper = createRef(); const handleTabsChange = (e, newValue) => { setValue(newValue); }; const handleDrawerClose = () => { setTimeout(() => { setOpenDrawer(false); }, 100); }; const routes = useMemo( () => [ { name: t.formatMessage({ id: "navigation.home", defaultMessage: "Home", }), link: "/", activeIndex: 0, }, { name: t.formatMessage({ id: "navigation.projects", defaultMessage: "Projects", }), link: "/projects", activeIndex: 1, }, { name: t.formatMessage({ id: "navigation.best-practices", defaultMessage: "Best Practices", }), link: "/best-practices", activeIndex: 2, }, { name: t.formatMessage({ id: "navigation.blog", defaultMessage: "Blog", }), link: "/blog", activeIndex: 3, }, { name: t.formatMessage({ id: "navigation.about", defaultMessage: "About", }), link: "/about", activeIndex: 4, }, ], [t] ); useEffect(() => { routes.forEach((route) => { switch (window.location.pathname) { case `${route.link}`: if (value !== route.activeIndex) { setValue(route.activeIndex); } break; default: return false; } }); }, [value, routes]); return ( setOpenDrawer(!openDrawer)} sx={{ color: theme.palette.text.secondary }}> {openDrawer ? : } {matches ? ( setOpenDrawer(true)} onClose={() => setOpenDrawer(false)} sx={{ backgroundColor: "transparent", }}> {routes.map((route) => ( { setValue(route.activeIndex); handleDrawerClose(); }} sx={{ padding: "1.5rem 2rem" }}> {route.name} ))} ) : ( {routes.map((route) => ( ))} )} ); }; export default Navigation;