2017-07-26 22:03:18 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Route, HashRouter, Redirect, Switch } from 'react-router-dom';
|
|
|
|
import { Home, ProjectGroups, Interface, News, AddInterface } from './containers/index';
|
|
|
|
import User from './containers/User/User.js';
|
|
|
|
import Header from './components/Header/Header';
|
|
|
|
import Footer from './components/Footer/Footer';
|
2017-07-30 15:06:03 +08:00
|
|
|
// import Breadcrumb from './components/Breadcrumb/Breadcrumb';
|
2017-07-26 22:03:18 +08:00
|
|
|
import Loading from './components/Loading/Loading';
|
|
|
|
import { checkLoginState } from './actions/login';
|
2017-07-24 11:35:31 +08:00
|
|
|
import { requireAuthentication } from './components/AuthenticatedComponent';
|
2017-07-20 19:59:49 +08:00
|
|
|
|
2017-07-19 16:24:37 +08:00
|
|
|
const LOADING_STATUS = 0;
|
|
|
|
|
2017-07-24 11:35:31 +08:00
|
|
|
@connect(
|
|
|
|
state => {
|
2017-07-26 22:03:18 +08:00
|
|
|
return {
|
|
|
|
loginState: state.login.loginState
|
|
|
|
};
|
2017-07-24 11:35:31 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
checkLoginState
|
|
|
|
}
|
|
|
|
)
|
|
|
|
export default class App extends Component {
|
2017-07-19 16:24:37 +08:00
|
|
|
constructor(props) {
|
2017-07-20 19:59:49 +08:00
|
|
|
super(props);
|
2017-07-19 16:24:37 +08:00
|
|
|
this.state = {
|
|
|
|
login: LOADING_STATUS
|
2017-07-26 22:03:18 +08:00
|
|
|
};
|
2017-07-19 16:24:37 +08:00
|
|
|
}
|
2017-07-26 22:03:18 +08:00
|
|
|
|
2017-07-20 19:59:49 +08:00
|
|
|
static propTypes = {
|
2017-07-26 22:03:18 +08:00
|
|
|
checkLoginState: PropTypes.func,
|
|
|
|
loginState: PropTypes.number
|
|
|
|
};
|
2017-07-24 11:35:31 +08:00
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.props.checkLoginState();
|
|
|
|
}
|
2017-07-26 22:03:18 +08:00
|
|
|
|
2017-07-19 16:24:37 +08:00
|
|
|
route = (status) => {
|
|
|
|
let r;
|
|
|
|
if (status === LOADING_STATUS) {
|
2017-07-26 22:03:18 +08:00
|
|
|
return <Loading visible />;
|
2017-07-19 16:24:37 +08:00
|
|
|
} else {
|
|
|
|
r = (
|
|
|
|
<HashRouter>
|
|
|
|
<div className="router-main">
|
|
|
|
<Header />
|
2017-07-26 16:20:20 +08:00
|
|
|
<div className="router-container">
|
2017-07-30 15:06:03 +08:00
|
|
|
{/* <Breadcrumb /> */}
|
2017-07-26 16:20:20 +08:00
|
|
|
<Route path="/" component={Home} exact />
|
|
|
|
<Switch>
|
|
|
|
<Redirect exact from='/group' to='/group/1' />
|
2017-07-26 22:03:18 +08:00
|
|
|
<Route exact path="/group/:groupName" component={requireAuthentication(ProjectGroups)} />
|
2017-07-26 16:20:20 +08:00
|
|
|
</Switch>
|
2017-07-28 17:30:56 +08:00
|
|
|
<Route path="/project" component={requireAuthentication(Interface)} />
|
2017-07-26 16:20:20 +08:00
|
|
|
<Route path="/user" component={requireAuthentication(User)} />
|
2017-07-28 17:35:14 +08:00
|
|
|
<Route path="/news" component={requireAuthentication(News)} />
|
2017-07-28 17:30:56 +08:00
|
|
|
<Route path="/add-interface" component={requireAuthentication(AddInterface)} />
|
2017-07-26 16:20:20 +08:00
|
|
|
</div>
|
2017-07-26 22:03:18 +08:00
|
|
|
<Footer />
|
2017-07-19 16:24:37 +08:00
|
|
|
</div>
|
|
|
|
</HashRouter>
|
|
|
|
)
|
|
|
|
}
|
2017-07-26 22:03:18 +08:00
|
|
|
return r;
|
2017-07-19 16:24:37 +08:00
|
|
|
}
|
2017-07-26 22:03:18 +08:00
|
|
|
|
2017-07-10 19:50:11 +08:00
|
|
|
render() {
|
2017-07-24 11:35:31 +08:00
|
|
|
return this.route(this.props.loginState);
|
2017-07-10 19:50:11 +08:00
|
|
|
}
|
|
|
|
}
|