2019-07-09 19:16:29 +09:00
|
|
|
import React from "react";
|
|
|
|
import { useRouter } from "next/router";
|
2020-02-09 00:07:54 +09:00
|
|
|
import Link from "next/link";
|
2019-12-13 15:04:55 +09:00
|
|
|
import AppBar from "@material-ui/core/AppBar";
|
|
|
|
import Tabs from "@material-ui/core/Tabs";
|
|
|
|
import Tab from "@material-ui/core/Tab";
|
2019-04-24 00:29:07 +09:00
|
|
|
import routes from "../routes";
|
2019-04-23 16:48:33 +09:00
|
|
|
|
2020-06-11 23:19:57 +09:00
|
|
|
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
|
|
|
|
|
2019-07-09 19:16:29 +09:00
|
|
|
const TopAppBar = () => {
|
|
|
|
const router = useRouter();
|
2020-06-11 23:19:57 +09:00
|
|
|
const currentPathname = React.useMemo(
|
|
|
|
() =>
|
|
|
|
router.pathname.startsWith(basePath)
|
|
|
|
? router.pathname.slice(basePath.length)
|
|
|
|
: router.pathname,
|
|
|
|
[router.pathname]
|
|
|
|
);
|
|
|
|
const tabPathname = React.useMemo(
|
|
|
|
() =>
|
|
|
|
routes.reduce(
|
|
|
|
(prev, { pathname }) =>
|
|
|
|
pathname === currentPathname ? pathname : prev,
|
|
|
|
"/"
|
|
|
|
),
|
|
|
|
[currentPathname]
|
|
|
|
);
|
2019-04-23 16:48:33 +09:00
|
|
|
return (
|
2019-07-09 15:46:11 +09:00
|
|
|
<AppBar color="default">
|
|
|
|
<Tabs
|
2020-06-11 23:19:57 +09:00
|
|
|
value={tabPathname}
|
2019-07-09 15:46:11 +09:00
|
|
|
variant="fullWidth"
|
|
|
|
indicatorColor="primary"
|
|
|
|
textColor="primary"
|
|
|
|
>
|
2020-06-11 23:19:57 +09:00
|
|
|
{routes.map(({ pathname, icon }, index) => (
|
2020-02-09 00:07:54 +09:00
|
|
|
<Tab
|
2020-06-11 23:19:57 +09:00
|
|
|
key={index}
|
2020-02-09 00:07:54 +09:00
|
|
|
value={pathname}
|
|
|
|
icon={icon}
|
2020-02-09 03:07:40 +09:00
|
|
|
component={React.forwardRef<HTMLAnchorElement, {}>((props, ref) => (
|
2020-06-11 22:10:26 +09:00
|
|
|
<Link href={pathname}>
|
2020-06-11 23:19:57 +09:00
|
|
|
<a ref={ref} href={[basePath, pathname].join("")} {...props} />
|
2020-02-09 00:07:54 +09:00
|
|
|
</Link>
|
2020-02-09 03:01:12 +09:00
|
|
|
))}
|
2020-02-09 00:07:54 +09:00
|
|
|
/>
|
2019-07-09 15:46:11 +09:00
|
|
|
))}
|
|
|
|
</Tabs>
|
|
|
|
</AppBar>
|
2019-04-23 16:48:33 +09:00
|
|
|
);
|
2019-07-09 19:16:29 +09:00
|
|
|
};
|
2019-07-09 15:46:11 +09:00
|
|
|
export default TopAppBar;
|