Created
October 19, 2016 22:37
-
-
Save Connorelsea/dcecc7f058566a88a520d4771814af4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from "react" | |
| import { connect } from 'react-redux' | |
| import App from "../../components/App/App" | |
| import LoginContainer from "../../containers/Login/LoginContainer" | |
| import { loginSuccess } from "../../redux/ducks/Login" | |
| import Router from 'react-router/BrowserRouter' | |
| import { Provider } from "react-redux" | |
| import DevTools from "../../redux/devtools" | |
| // Login Container | |
| type Props = { | |
| isAuthenticated: boolean, | |
| loginSuccess: func, | |
| store: object, | |
| }; | |
| class AppContainer extends Component { | |
| props: Props; | |
| componentWillMount() { | |
| if (!this.props.isAuthenticated && localStorage.getItem("isAuthenticated")) { | |
| console.log("WILL MOUNT: AppContainer -> Setting Auth") | |
| this.props.loginSuccess({ | |
| profileObj: localStorage.getItem("profileObj"), | |
| tokenObj: localStorage.getItem("tokenObj"), | |
| tokenId: localStorage.getItem("tokenId"), | |
| }) | |
| } | |
| } | |
| render() { | |
| console.log("RENDER: AppContainer") | |
| return ( | |
| <div className="App-Container"> | |
| <Provider store={this.props.store} > | |
| <Router> | |
| <div> | |
| {this.props.isAuthenticated | |
| ? "AUTH YEAH" | |
| : <LoginContainer />} | |
| <DevTools /> | |
| </div> | |
| </Router> | |
| </Provider> | |
| </div> | |
| ) | |
| } | |
| } | |
| // Redux State Transformation | |
| const mapStateToProps = function(state) { | |
| return { | |
| isAuthenticated: state.Login.isAuthenticated, | |
| } | |
| } | |
| const mapDispatchToProps = function(dispatch, ownProps) { | |
| return { | |
| loginSuccess: (user) => { | |
| dispatch(loginSuccess(user)) | |
| }, | |
| } | |
| } | |
| export default connect(mapStateToProps, mapDispatchToProps)(AppContainer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment