// @flow import React, { Component } from "react"; import Main from "./Main"; import { connect } from "react-redux"; import { translate } from "react-i18next"; import { withRouter } from "react-router-dom"; import { fetchMe, isAuthenticated, getMe, isFetchMePending, getFetchMeFailure } from "../modules/auth"; import { PrimaryNavigation } from "../components/navigation"; import Loading from "../components/Loading"; import ErrorPage from "../components/ErrorPage"; import { Footer, Header } from "../components/layout"; import type { Me } from "../types/Me"; type Props = { me: Me, authenticated: boolean, error: Error, loading: boolean, // dispatcher functions fetchMe: () => void, // context props t: string => string }; class App extends Component { componentDidMount() { this.props.fetchMe(); } render() { const { me, loading, error, authenticated, t } = this.props; let content; const navigation = authenticated ? : ""; if (loading) { content = ; } else if (error) { content = ( ); } else { content =
; } return (
{navigation}
{content}
); } } const mapDispatchToProps = (dispatch: any) => { return { fetchMe: () => dispatch(fetchMe()) }; }; const mapStateToProps = state => { const authenticated = isAuthenticated(state); const me = getMe(state); const loading = isFetchMePending(state); const error = getFetchMeFailure(state); return { authenticated, me, loading, error }; }; export default withRouter( connect( mapStateToProps, mapDispatchToProps )(translate("commons")(App)) );