1import React from 'react';
2import { Link } from 'react-router-dom';
3
4import AppBar from '@material-ui/core/AppBar';
5import Tab from '@material-ui/core/Tab';
6import Tabs from '@material-ui/core/Tabs';
7import Toolbar from '@material-ui/core/Toolbar';
8import { makeStyles } from '@material-ui/core/styles';
9
10import { LightSwitch } from '../../components/Themer';
11import CurrentIdentity from '../CurrentIdentity/CurrentIdentity';
12
13const useStyles = makeStyles((theme) => ({
14 offset: {
15 ...theme.mixins.toolbar,
16 },
17 filler: {
18 flexGrow: 1,
19 },
20 appBar: {
21 backgroundColor: theme.palette.primary.dark,
22 color: theme.palette.primary.contrastText,
23 },
24 appTitle: {
25 ...theme.typography.h6,
26 color: theme.palette.primary.contrastText,
27 textDecoration: 'none',
28 display: 'flex',
29 alignItems: 'center',
30 },
31 lightSwitch: {
32 padding: '0 20px',
33 },
34 logo: {
35 height: '42px',
36 marginRight: theme.spacing(2),
37 },
38}));
39
40function a11yProps(index: any) {
41 return {
42 id: `nav-tab-${index}`,
43 'aria-controls': `nav-tabpanel-${index}`,
44 };
45}
46
47function NavTabs() {
48 const [value, setValue] = React.useState(0);
49
50 //TODO page refresh resets state. Must parse url to determine which tab is
51 //highlighted
52 const handleChange = (event: React.ChangeEvent<{}>, newValue: number) => {
53 setValue(newValue);
54 };
55
56 return (
57 <Tabs
58 variant="fullWidth"
59 value={value}
60 onChange={handleChange}
61 aria-label="nav tabs example"
62 >
63 <Tab label="Code" component="a" href="/code" {...a11yProps(0)} />
64 <Tab label="Bugs" component="a" href="/" {...a11yProps(1)} />
65 <Tab
66 label="Pull Requests"
67 component="a"
68 href="/pulls"
69 {...a11yProps(2)}
70 />
71 <Tab label="Projects" component="a" href="/projects" {...a11yProps(3)} />
72 <Tab label="Wiki" component="a" href="/wiki" {...a11yProps(4)} />
73 <Tab label="Settings" component="a" href="/settings" {...a11yProps(5)} />
74 </Tabs>
75 );
76}
77
78function Header() {
79 const classes = useStyles();
80
81 return (
82 <>
83 <AppBar position="fixed" className={classes.appBar}>
84 <Toolbar>
85 <Link to="/" className={classes.appTitle}>
86 <img src="/logo.svg" className={classes.logo} alt="git-bug" />
87 git-bug
88 </Link>
89 <div className={classes.filler} />
90 <div className={classes.lightSwitch}>
91 <LightSwitch />
92 </div>
93 <CurrentIdentity />
94 </Toolbar>
95 </AppBar>
96 <div className={classes.offset} />
97 <NavTabs />
98 </>
99 );
100}
101
102export default Header;