Created
October 21, 2016 14:39
-
-
Save bnhansn/008917480fcc03e31f4b093b7189ede4 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
| // @flow | |
| import React, { Component, PropTypes } from 'react'; | |
| import { connect } from 'react-redux'; | |
| import { Link } from 'react-router'; | |
| import { logout } from '../../actions/session'; | |
| import Navbar from '../../components/Navbar'; | |
| type Props = { | |
| logout: () => void, | |
| currentUser: Object, | |
| isAuthenticated: boolean, | |
| } | |
| class Home extends Component { | |
| static contextTypes = { | |
| router: PropTypes.object, | |
| } | |
| props: Props | |
| handleLogout = () => this.props.logout(this.context.router); | |
| render() { | |
| const { currentUser, isAuthenticated } = this.props; | |
| return ( | |
| <div style={{ flex: '1' }}> | |
| <Navbar /> | |
| <ul> | |
| <li><Link to="/login">Login</Link></li> | |
| <li><Link to="/signup">Signup</Link></li> | |
| </ul> | |
| {isAuthenticated && | |
| <div> | |
| <span>{currentUser.username}</span> | |
| <button type="button" onClick={this.handleLogout}>Logout</button> | |
| </div> | |
| } | |
| </div> | |
| ); | |
| } | |
| } | |
| export default connect( | |
| state => ({ | |
| isAuthenticated: state.session.isAuthenticated, | |
| currentUser: state.session.currentUser, | |
| }), | |
| { logout } | |
| )(Home); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment