-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdmin.js
More file actions
137 lines (127 loc) · 4.02 KB
/
Copy pathAdmin.js
File metadata and controls
137 lines (127 loc) · 4.02 KB
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
import React from "react";
import { Switch, Route, Redirect } from "react-router-dom";
// creates a beautiful scrollbar
import PerfectScrollbar from "perfect-scrollbar";
import "perfect-scrollbar/css/perfect-scrollbar.css";
// @material-ui/core components
import { makeStyles } from "@material-ui/core/styles";
// core components
import Navbar from "../components/Navbars/Navbar.js";
import Footer from "../components/Footer/Footer.js";
import Sidebar from "../components/Sidebar/Sidebar.js";
import FixedPlugin from "../components/FixedPlugin/FixedPlugin.js";
import routes from "../routes.js";
import styles from "../assets/jss/material-dashboard-react/layouts/adminStyle.js";
import bgImage from "../assets/img/sidebar-2.jpg";
import logo from "../assets/img/reactlogo.png";
let ps;
const switchRoutes = (
<Switch>
{routes.map((prop, key) => {
console.log(prop)
if (prop.layout === "/admin") {
return (
<Route
path={prop.layout + prop.path}
component={prop.component}
key={key}
/>
);
}
return null;
})}
<Redirect from="/admin" to="/admin/dashboard" />
</Switch>
);
const useStyles = makeStyles(styles);
export default function Admin({ ...rest }) {
// styles
const classes = useStyles();
// ref to help us initialize PerfectScrollbar on windows devices
const mainPanel = React.createRef();
// states and functions
const [image, setImage] = React.useState(bgImage);
const [color, setColor] = React.useState("blue");
const [fixedClasses, setFixedClasses] = React.useState("dropdown show");
const [mobileOpen, setMobileOpen] = React.useState(false);
const handleImageClick = image => {
setImage(image);
};
const handleColorClick = color => {
setColor(color);
};
const handleFixedClick = () => {
if (fixedClasses === "dropdown") {
setFixedClasses("dropdown show");
} else {
setFixedClasses("dropdown");
}
};
const handleDrawerToggle = () => {
setMobileOpen(!mobileOpen);
};
const getRoute = () => {
return window.location.pathname !== "/admin/maps";
};
const resizeFunction = () => {
if (window.innerWidth >= 960) {
setMobileOpen(false);
}
};
// initialize and destroy the PerfectScrollbar plugin
React.useEffect(() => {
if (navigator.platform.indexOf("Win") > -1) {
ps = new PerfectScrollbar(mainPanel.current, {
suppressScrollX: true,
suppressScrollY: false
});
document.body.style.overflow = "hidden";
}
window.addEventListener("resize", resizeFunction);
// Specify how to clean up after this effect:
return function cleanup() {
if (navigator.platform.indexOf("Win") > -1) {
ps.destroy();
}
window.removeEventListener("resize", resizeFunction);
};
}, [mainPanel]);
return (
<div className={classes.wrapper}>
<Sidebar
routes={routes}
logoText={"Recce Labs"}
logo={logo}
image={image}
handleDrawerToggle={handleDrawerToggle}
open={mobileOpen}
color={color}
{...rest}
/>
<div className={classes.mainPanel} ref={mainPanel}>
<Navbar
routes={routes}
handleDrawerToggle={handleDrawerToggle}
{...rest}
/>
{/* On the /maps route we want the map to be on full screen - this is not possible if the content and conatiner classes are present because they have some paddings which would make the map smaller */}
{getRoute() ? (
<div className={classes.content}>
<div className={classes.container}>{switchRoutes}</div>
</div>
) : (
<div className={classes.map}>{switchRoutes}</div>
)}
{getRoute() ? <Footer /> : null}
<FixedPlugin
handleImageClick={handleImageClick}
handleColorClick={handleColorClick}
bgColor={color}
bgImage={image}
handleFixedClick={handleFixedClick}
fixedClasses={fixedClasses}
/>
</div>
</div>
);
}