// @flow import type { List } from 'immutable'; import React, { Component } from 'react'; import { connect } from 'react-redux'; import { InlineForm, Space, Text } from 'rebass'; import { Flex } from 'reflexbox'; import { GameList } from '../../components/gameList'; import type { Game } from '../../models/games'; import type { Player } from '../../models/players'; import { actions, getAllGames } from '../../redux/games'; import { getCurrentPlayer } from '../../redux/players'; class GameBrowserPresenter extends Component { props: { currentPlayer: Player, games: List, createGame: (gameName: string) => void, joinGame: (gameId: string) => void }; _gameName: string | void = undefined; createGame = (e: SyntheticEvent): void => { e.preventDefault(); if (this._gameName !== undefined) { this.props.createGame(this._gameName); } }; render() { return (
(this._gameName = e.target.value)} onClick={this.createGame} /> Username: {' '} {this.props.currentPlayer && this.props.currentPlayer.displayName}
); } } const mapStateToProps = state => ({ currentPlayer: getCurrentPlayer(state.get('players')), games: getAllGames(state.get('games')), }); const mapDispatchToProps = { createGame: actions.requestCreateGame, joinGame: actions.requestJoinGame, }; export const GameBrowser = connect(mapStateToProps, mapDispatchToProps)(GameBrowserPresenter);