yapi/client/Application.js

82 lines
2.3 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
2017-08-11 11:26:49 +08:00
import { Route, BrowserRouter as Router } from 'react-router-dom';
2017-08-10 21:03:22 +08:00
import { Home, Group, Project, Follows, AddProject } from './containers/index';
import User from './containers/User/User.js';
import Header from './components/Header/Header';
import Footer from './components/Footer/Footer';
import Loading from './components/Loading/Loading';
2017-08-10 20:08:23 +08:00
import { checkLoginState } from './reducer/modules/user';
import { requireAuthentication } from './components/AuthenticatedComponent';
2017-07-19 16:24:37 +08:00
const LOADING_STATUS = 0;
@connect(
state => {
return {
2017-08-10 20:08:23 +08:00
loginState: state.user.loginState
};
},
{
checkLoginState
}
)
export default class App extends Component {
2017-07-19 16:24:37 +08:00
constructor(props) {
super(props);
2017-07-19 16:24:37 +08:00
this.state = {
login: LOADING_STATUS
};
2017-07-19 16:24:37 +08:00
}
static propTypes = {
checkLoginState: PropTypes.func,
loginState: PropTypes.number
};
2017-08-10 20:08:23 +08:00
// componentWillMount() {
// if( !this.props.isAuthenticated ){
// this.props.history.push('/');
// this.props.changeMenuItem('/');
// }
// }
componentDidMount() {
this.props.checkLoginState();
}
2017-07-19 16:24:37 +08:00
route = (status) => {
let r;
if (status === LOADING_STATUS) {
return <Loading visible />;
2017-07-19 16:24:37 +08:00
} else {
r = (
<Router>
2017-07-19 16:24:37 +08:00
<div className="router-main">
<Header />
2017-07-26 16:20:20 +08:00
<div className="router-container">
2017-08-11 15:02:07 +08:00
<Route exact path="/" component={Home} />
2017-08-11 11:34:55 +08:00
<Route path="/group" component={requireAuthentication(Group)} />
2017-08-11 16:03:11 +08:00
<Route path="/project/:id" component={requireAuthentication(Project)} />
2017-07-26 16:20:20 +08:00
<Route path="/user" component={requireAuthentication(User)} />
2017-08-08 16:21:32 +08:00
<Route path="/follow" component={requireAuthentication(Follows)} />
2017-08-10 18:26:35 +08:00
<Route path="/add-project" component={requireAuthentication(AddProject)} />
2017-08-10 21:03:22 +08:00
{
// <Route path="/news" component={requireAuthentication(News)} />
// <Route path="/add-interface" component={requireAuthentication(AddInterface)} />
}
2017-07-26 16:20:20 +08:00
</div>
<Footer />
2017-07-19 16:24:37 +08:00
</div>
</Router>
2017-07-19 16:24:37 +08:00
)
}
return r;
2017-07-19 16:24:37 +08:00
}
2017-07-10 19:50:11 +08:00
render() {
return this.route(this.props.loginState);
2017-07-10 19:50:11 +08:00
}
}