Files
SCM-Manager/scm-ui/src/containers/App.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

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