1import React from 'react';
2import { Link, useLocation } from 'react-router-dom';
3
4import AppBar from '@material-ui/core/AppBar';
5import Tab, { TabProps } from '@material-ui/core/Tab';
6import Tabs from '@material-ui/core/Tabs';
7import Toolbar from '@material-ui/core/Toolbar';
8import Tooltip from '@material-ui/core/Tooltip/Tooltip';
9import { makeStyles } from '@material-ui/core/styles';
10
11import { LightSwitch } from '../../components/Themer';
12import CurrentIdentity from '../CurrentIdentity/CurrentIdentity';
13
14const useStyles = makeStyles((theme) => ({
15 offset: {
16 ...theme.mixins.toolbar,
17 },
18 filler: {
19 flexGrow: 1,
20 },
21 appBar: {
22 backgroundColor: theme.palette.primary.dark,
23 color: theme.palette.primary.contrastText,
24 },
25 appTitle: {
26 ...theme.typography.h6,
27 color: theme.palette.primary.contrastText,
28 textDecoration: 'none',
29 display: 'flex',
30 alignItems: 'center',
31 },
32 lightSwitch: {
33 padding: '0 20px',
34 },
35 logo: {
36 height: '42px',
37 marginRight: theme.spacing(2),
38 },
39}));
40
41function a11yProps(index: any) {
42 return {
43 id: `nav-tab-${index}`,
44 'aria-controls': `nav-tabpanel-${index}`,
45 };
46}
47
48const DisabledTabWithTooltip = (props: TabProps) => {
49 /*The span elements around disabled tabs are needed, as the tooltip
50 * won't be triggered by disabled elements.
51 * See: https://material-ui.com/components/tooltips/#disabled-elements
52 * This must be done in a wrapper component, otherwise the TabS component
53 * cannot pass it styles down to the Tab component. Resulting in (console)
54 * warnings. This wrapper acceps the passed down TabProps and pass it around
55 * the span element to the Tab component.
56 */
57 const msg = `This feature doesn't exist yet. Come help us build it.`;
58 console.log(props);
59 return (
60 <Tooltip title={msg}>
61 <span>
62 <Tab disabled {...props} />
63 </span>
64 </Tooltip>
65 );
66};
67
68function Header() {
69 const classes = useStyles();
70 const location = useLocation();
71 const [selectedTab, setTab] = React.useState(location.pathname);
72 console.log(location.pathname);
73
74 const handleTabClick = (
75 event: React.ChangeEvent<{}>,
76 newTabValue: string
77 ) => {
78 setTab(newTabValue);
79 };
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 logo" />
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 <Tabs
98 centered
99 value={selectedTab}
100 onChange={handleTabClick}
101 aria-label="nav tabs"
102 >
103 <DisabledTabWithTooltip label="Code" value="/code" {...a11yProps(1)} />
104 <Tab label="Bugs" value="/" href="/" {...a11yProps(2)} />
105 <DisabledTabWithTooltip
106 label="Pull Requests"
107 value="/pulls"
108 {...a11yProps(3)}
109 />
110 <DisabledTabWithTooltip
111 label="Settings"
112 value="/settings"
113 {...a11yProps(4)}
114 />
115 </Tabs>
116 </>
117 );
118}
119
120export default Header;