-
Notifications
You must be signed in to change notification settings - Fork 1
/
MuiSideDrawer.js
372 lines (352 loc) · 10.9 KB
/
MuiSideDrawer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
import React, { Component } from "react";
import { connect } from "react-redux";
import clsx from "clsx";
// Material UI imports
import AppBar from "@material-ui/core/AppBar";
import Button from "@material-ui/core/Button";
import Drawer from "@material-ui/core/Drawer";
import Hidden from "@material-ui/core/Hidden";
import Toolbar from "@material-ui/core/Toolbar";
import Divider from "@material-ui/core/Divider";
import SvgIcon from "@material-ui/core/SvgIcon";
import Typography from "@material-ui/core/Typography";
import IconButton from "@material-ui/core/IconButton";
import CssBaseline from "@material-ui/core/CssBaseline";
import { withStyles } from "@material-ui/core/styles";
// Material UI List related imports
import List from "@material-ui/core/List";
import ListItem from "@material-ui/core/ListItem";
import ListItemIcon from "@material-ui/core/ListItemIcon";
import ListItemText from "@material-ui/core/ListItemText";
// Material UI icon imports
import HomeIcon from "@material-ui/icons/Home";
import InfoIcon from "@material-ui/icons/Info";
import MenuIcon from "@material-ui/icons/Menu";
import GitHubIcon from "@material-ui/icons/GitHub";
import SearchIcon from "@material-ui/icons/Search";
import DescriptionIcon from "@material-ui/icons/Description";
import ChevronLeftIcon from "@material-ui/icons/ChevronLeft";
import ChevronRightIcon from "@material-ui/icons/ChevronRight";
import ChromeReaderModeIcon from "@material-ui/icons/ChromeReaderMode";
// Material Design Icon import
import { mdiApi } from "@mdi/js";
import { mdiTestTube } from "@mdi/js";
// React Router Dom import
import { Link } from "react-router-dom";
const drawerWidth = 240;
const styles = (theme) => ({
root: {
display: "flex",
},
appBar: {
zIndex: theme.zIndex.drawer + 1,
transition: theme.transitions.create(["margin", "width"], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
},
appBarShift: {
marginLeft: drawerWidth,
width: `calc(100% - ${drawerWidth}px)`,
transition: theme.transitions.create(["margin", "width"], {
easing: theme.transitions.easing.easeOut,
duration: theme.transitions.duration.enteringScreen,
}),
},
menuButton: {
marginRight: 36,
},
hide: {
display: "none",
},
drawer: {
width: drawerWidth,
flexShrink: 0,
whiteSpace: "nowrap",
},
drawerOpen: {
backgroundColor: "#3b3b3b",
color: "white",
width: drawerWidth,
transition: theme.transitions.create("width", {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen,
}),
[theme.breakpoints.up("md")]: {
position: "relative",
},
},
drawerClose: {
backgroundColor: "#3b3b3b",
color: "white",
transition: theme.transitions.create("width", {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
overflowX: "hidden",
width: theme.spacing(7) + 1,
[theme.breakpoints.up("sm")]: {
width: theme.spacing(9) + 1,
},
},
drawerPaper: {
width: drawerWidth,
backgroundColor: "#3b3b3b",
color: "white",
},
drawerHeader: {
display: "flex",
alignItems: "center",
padding: theme.spacing(0, 1),
...theme.mixins.toolbar,
justifyContent: "flex-end",
},
content: {
flexGrow: 1,
padding: theme.spacing(3),
marginTop: "10px",
},
title: {
flexGrow: 1,
},
});
class PersistentDrawerLeft extends Component {
constructor(props) {
super(props);
this.state = {
open: false,
hoverOpen: false,
};
this.mouseOverTimer = null;
}
handleDrawerOpen = () => {
this.setState({ open: true });
};
handleDrawerClose = () => {
this.setState({ open: false });
};
scheduleMouseOver = () => {
if (this.state.open === false && this.state.hoverOpen === false) {
this.mouseOverTimer = setTimeout(() => {
this.handleDrawerOpen();
}, 350);
this.setState({ hoverOpen: true });
}
};
cancelMouseOver = () => {
if (this.state.hoverOpen === true) {
this.handleDrawerClose();
this.setState({ hoverOpen: false });
}
if (this.state.mouseOverTimer) {
clearTimeout(this.mouseOverTimer);
this.mouseOverTimer = null;
}
};
render() {
const { classes } = this.props;
const drawer = (
<div>
<div className={classes.toolbar}>
<Divider />
<List>
<ListItem button component={Link} to="/">
<ListItemIcon>
<HomeIcon style={{ color: "white" }} />
</ListItemIcon>
<ListItemText primary={"Home"} />
</ListItem>
<ListItem button component={Link} to="/stats">
<ListItemIcon>
<DescriptionIcon style={{ color: "white" }} />
</ListItemIcon>
<ListItemText primary={"Schemas"} />
</ListItem>
<ListItem button component={Link} to="/sequences">
<ListItemIcon>
<SearchIcon style={{ color: "white" }} />
</ListItemIcon>
<ListItemText primary={"Search"} />
</ListItem>
<ListItem button component={Link} to="/about">
<ListItemIcon>
<InfoIcon style={{ color: "white" }} />
</ListItemIcon>
<ListItemText primary={"About Us"} />
</ListItem>
</List>
<Divider />
<List>
<ListItem
button
component="a"
href={
"https://github.com/B-UMMI/Chewie-NS"
}
target={"_blank"}
rel="noopener noreferrer"
>
<ListItemIcon>
<GitHubIcon style={{ color: "white" }} />
</ListItemIcon>
<ListItemText primary={"Github"} />
</ListItem>
<ListItem
button
component="a"
href={"https://chewie-ns.readthedocs.io/en/latest/"}
target={"_blank"}
rel="noopener noreferrer"
>
<ListItemIcon>
<ChromeReaderModeIcon style={{ color: "white" }} />
</ListItemIcon>
<ListItemText primary={"Read The Docs"} />
</ListItem>
<ListItem
button
component="a"
href={"https://chewbbaca.online/api/NS/api/docs"}
target={"_blank"}
rel="noopener noreferrer"
>
<ListItemIcon>
<SvgIcon fontSize="large" htmlColor="#ffffff">
{" "}
<path d={mdiApi} />{" "}
</SvgIcon>
</ListItemIcon>
<ListItemText primary={"API"} />
</ListItem>
<ListItem
button
component="a"
href={"https://tutorial.chewbbaca.online/"}
target={"_blank"}
rel="noopener noreferrer"
>
<ListItemIcon>
<SvgIcon fontSize="large" htmlColor="#ffffff">
{" "}
<path d={mdiTestTube} />{" "}
</SvgIcon>
</ListItemIcon>
<ListItemText primary={"Tutorial"} />
</ListItem>
</List>
</div>
</div>
);
const container =
window !== undefined ? () => window.document.body : undefined;
return (
<div className={classes.root}>
<CssBaseline />
<AppBar
position="fixed"
className={clsx(classes.appBar, {
[classes.appBarShift]: this.state.open,
})}
color="primary"
style={{ backgroundColor: "#3b3b3b" }}
>
<Toolbar>
<IconButton
color="inherit"
aria-label="open drawer"
onClick={() => this.handleDrawerOpen()}
edge="start"
className={clsx(
classes.menuButton,
this.state.open && classes.hide
)}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" className={classes.title}>
Chewie-NS
</Typography>
{!this.props.isAuthenticated ? (
<Button color="inherit" component={Link} to="/auth">
Login
</Button>
) : (
<Button color="inherit" component={Link} to="/logout">
Logout
</Button>
)}
</Toolbar>
</AppBar>
<Hidden smUp implementation="css">
<Drawer
container={container}
variant="temporary"
anchor={this.props.theme.direction === "rtl" ? "right" : "left"}
open={this.state.open}
onClose={() => this.handleDrawerClose()}
classes={{
paper: classes.drawerPaper,
}}
ModalProps={{
keepMounted: true, // Better open performance on mobile.
}}
>
<div className={classes.drawerHeader}>
<IconButton onClick={() => this.handleDrawerClose()}>
{this.props.theme.direction === "ltr" ? (
<ChevronLeftIcon style={{ color: "white" }} />
) : (
<ChevronRightIcon style={{ color: "white" }} />
)}
</IconButton>
</div>
{drawer}
</Drawer>
</Hidden>
<Hidden xsDown implementation="css">
<Drawer
variant="permanent"
open={this.state.open}
className={clsx(classes.drawer, {
[classes.drawerOpen]: this.state.open,
[classes.drawerClose]: !this.state.open,
})}
classes={{
paper: clsx({
[classes.drawerOpen]: this.state.open,
[classes.drawerClose]: !this.state.open,
}),
}}
>
<div className={classes.drawerHeader}>
<IconButton onClick={() => this.handleDrawerClose()}>
{this.props.theme.direction === "ltr" ? (
<ChevronLeftIcon style={{ color: "white" }} />
) : (
<ChevronRightIcon style={{ color: "white" }} />
)}
</IconButton>
</div>
{drawer}
</Drawer>
</Hidden>
<main className={classes.content}>
<div className={classes.drawerHeader} />
{this.props.children}
</main>
</div>
);
}
}
const mapStateToProps = (state) => {
return {
loading: state.auth.loading,
error: state.auth.error,
isAuthenticated: state.auth.token !== null,
authRedirectPath: state.auth.authRedirectPath,
};
};
export default connect(
mapStateToProps,
null
)(withStyles(styles, { withTheme: true })(PersistentDrawerLeft));