-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
78 lines (71 loc) · 2.48 KB
/
index.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
import React from 'react';
import { render } from 'react-dom';
import { Router, Route, browserHistory, IndexRoute } from 'react-router';
import { MainSurface } from './app/components/MainSurface';
import { SurfaceArea } from './app/components/SurfaceArea';
import { Root } from './app/pages/Root';
import { Login } from './app/pages/Login';
import { Register } from './app/pages/Register';
import { Dashboard } from './app/pages/components/Dashboard';
import { Modules } from './app/pages/components/Modules';
import { Users } from './app/pages/components/Users';
import { Profile } from './app/pages/components/Profile';
import { ModuleProfile } from './app/pages/components/ModuleProfile';
import { isLoggedIn, requireAuth } from './app/utils/AuthService';
import { NotFound } from './app/pages/components/mini-components/NotFound';
import { NoInternet } from './app/pages/components/mini-components/NoInternet';
import { getModules } from './app/utils/modules-api';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoggedIn: isLoggedIn(),
online: ''
}
}
componentDidMount() {
getModules()
.then((response) => {
if(response) {
this.setState({
online: "online"
});
} else {
console.log("error");
this.setState({
online: "offline"
})
}
}).catch((error) => {
if(!navigator.online) {
this.setState({
online: "offline"
})
}
});
}
render() {
var { online } = this.state;
console.log(online);
return(
(online == "offline") ? <NoInternet /> :
<Router history={browserHistory}>
<Route path={"/"} component={MainSurface}>
<IndexRoute component={SurfaceArea} />
</Route>
<Route path={"/dashboard"} component={Root} onEnter={requireAuth}>
<IndexRoute component={Dashboard} />
<Route path="/modules" component={Modules} />
<Route path="/users" component={Users} />
<Route path="/profile" component={Profile} />
<Route path="/modules/:id" component={ModuleProfile} />
<Route path="*" component={NotFound} />
</Route>
<Route path="login" component={Login} />
<Route path="register" component={Register} />
<Route path="*" component={NotFound} />
</Router>
);
}
}
render(<App />, window.document.getElementById('root'));