diff --git a/styles/TopAppBar.tsx b/styles/TopAppBar.tsx index 61a5267..3738d73 100644 --- a/styles/TopAppBar.tsx +++ b/styles/TopAppBar.tsx @@ -1,29 +1,45 @@ -import React from "react"; -import Link from "next/link"; +import React, { useState } from "react"; +import { withRouter } from "next/router"; import { makeStyles } from "@material-ui/styles"; -import { AppBar, Toolbar, IconButton } from "@material-ui/core"; -import { Home } from "@material-ui/icons"; +import { AppBar, Tabs, Tab } from "@material-ui/core"; +import { Home, Info } from "@material-ui/icons"; -const useStyles = makeStyles({ - root: { - flexGrow: 1 - } -}); +export const routes = [ + { pathname: "/", icon: }, + { pathname: "/about", icon: } +]; -const TopAppBar: React.FC = () => { - const classes = useStyles(); +const TopAppBar: React.FC<{ router: any }> = ({ router }) => { + const classes = makeStyles({ + root: { + flexGrow: 1 + } + })(); + const [value, setValue] = useState( + routes.findIndex(({ pathname }) => pathname === router.pathname) + ); + router.events.on("routeChangeStart", (url: string) => { + setValue(routes.findIndex(({ pathname }) => pathname === url)); + }); return (
- - - - - - - + { + router.push(routes[value].pathname); + setValue(value); + }} + variant="fullWidth" + indicatorColor="primary" + textColor="primary" + > + {routes.map(({ icon }, i) => ( + + ))} +
); }; -export default TopAppBar; +export default withRouter(TopAppBar);