2018-07-04 16:43:46 +02:00
|
|
|
import React, { Component } from "react";
|
|
|
|
|
import Main from "./Main";
|
|
|
|
|
import Login from "./Login";
|
2018-07-09 11:38:13 +02:00
|
|
|
import { getIsAuthenticated } from "../modules/login";
|
|
|
|
|
import { connect } from "react-redux";
|
2018-07-04 16:43:46 +02:00
|
|
|
import { withRouter } from "react-router-dom";
|
2018-07-11 17:02:38 +02:00
|
|
|
import { ThunkDispatch } from "redux-thunk";
|
2018-07-04 16:43:46 +02:00
|
|
|
|
2018-07-11 14:59:01 +02:00
|
|
|
import "./App.css";
|
|
|
|
|
import Header from "../components/Header";
|
|
|
|
|
import PrimaryNavigation from "../components/PrimaryNavigation";
|
|
|
|
|
|
2018-07-04 16:43:46 +02:00
|
|
|
type Props = {
|
2018-07-09 11:38:13 +02:00
|
|
|
login: boolean,
|
|
|
|
|
username: string,
|
2018-07-11 12:02:53 +02:00
|
|
|
getAuthState: () => void,
|
|
|
|
|
loading: boolean
|
2018-07-05 16:48:56 +02:00
|
|
|
};
|
2018-07-04 16:43:46 +02:00
|
|
|
|
2018-07-11 12:02:53 +02:00
|
|
|
class App extends Component<Props> {
|
|
|
|
|
componentDidMount() {
|
2018-07-09 11:38:13 +02:00
|
|
|
this.props.getAuthState();
|
|
|
|
|
}
|
2018-07-04 16:43:46 +02:00
|
|
|
render() {
|
2018-07-11 14:59:01 +02:00
|
|
|
const { login, loading } = this.props;
|
|
|
|
|
|
|
|
|
|
let content;
|
|
|
|
|
let navigation;
|
|
|
|
|
|
2018-07-11 12:02:53 +02:00
|
|
|
if (loading) {
|
2018-07-11 14:59:01 +02:00
|
|
|
content = <div>Loading...</div>;
|
2018-07-11 12:02:53 +02:00
|
|
|
} else if (!login) {
|
2018-07-11 14:59:01 +02:00
|
|
|
content = <Login />;
|
2018-07-05 16:48:56 +02:00
|
|
|
} else {
|
2018-07-11 14:59:01 +02:00
|
|
|
content = <Main />;
|
|
|
|
|
navigation = <PrimaryNavigation />;
|
2018-07-05 16:48:56 +02:00
|
|
|
}
|
2018-07-11 14:59:01 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="App">
|
|
|
|
|
<Header>{navigation}</Header>
|
|
|
|
|
{content}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2018-07-04 16:43:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-11 17:02:38 +02:00
|
|
|
const mapDispatchToProps = (dispatch: ThunkDispatch) => {
|
2018-07-09 11:38:13 +02:00
|
|
|
return {
|
|
|
|
|
getAuthState: () => dispatch(getIsAuthenticated())
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
2018-07-11 12:02:53 +02:00
|
|
|
return state.login || {};
|
2018-07-09 11:38:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default withRouter(
|
|
|
|
|
connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
|
|
|
|
)(App)
|
|
|
|
|
);
|