yapi/client/Application.js

70 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-07-10 19:50:11 +08:00
import React, { Component } from 'react'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
2017-07-25 18:08:12 +08:00
import { Route, HashRouter, Redirect, Switch } from 'react-router-dom'
import { Home, ProjectGroups, Interface, News, AddInterface } from './containers/index'
2017-07-19 16:24:37 +08:00
import User from './containers/User/User.js'
import Header from './components/Header/Header'
2017-07-25 18:11:53 +08:00
import Footer from './components/Footer/Footer'
import Loading from './components/Loading/Loading'
import { checkLoginState } from './actions/login'
import { requireAuthentication } from './components/AuthenticatedComponent';
2017-07-19 16:24:37 +08:00
const LOADING_STATUS = 0;
@connect(
state => {
return{
loginState:state.login.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
}
}
static propTypes = {
checkLoginState:PropTypes.func,
loginState:PropTypes.number
}
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 = (
<HashRouter>
<div className="router-main">
<Header />
<Route path="/" component={Home} exact />
2017-07-25 18:08:12 +08:00
{/*<Route exact path="/group" component={ requireAuthentication(ProjectGroups) } ></Route>*/}
<Switch>
<Redirect exact from='/group' to='/group/1' />
<Route exact path="/group/:groupName" component={ requireAuthentication(ProjectGroups) } />
</Switch>
<Route path="/Interface" component={requireAuthentication(Interface)} />
<Route path="/user" component={requireAuthentication(User)} />
<Route path="/News" component={requireAuthentication(News)} />
<Route path="/AddInterface" component={ requireAuthentication(AddInterface) } />
2017-07-25 18:11:53 +08:00
<Footer/>
2017-07-19 16:24:37 +08:00
</div>
</HashRouter>
)
}
return r
}
2017-07-10 19:50:11 +08:00
render() {
return this.route(this.props.loginState);
2017-07-10 19:50:11 +08:00
}
}