diff options
Diffstat (limited to 'frontend/src/components')
-rw-r--r-- | frontend/src/components/PlayerInfo.jsx | 27 | ||||
-rw-r--r-- | frontend/src/components/game-browser/GameBrowser.jsx | 54 | ||||
-rw-r--r-- | frontend/src/components/game-browser/GameList.jsx | 37 | ||||
-rw-r--r-- | frontend/src/components/gameList.js | 19 |
4 files changed, 118 insertions, 19 deletions
diff --git a/frontend/src/components/PlayerInfo.jsx b/frontend/src/components/PlayerInfo.jsx new file mode 100644 index 00000000..42d3142a --- /dev/null +++ b/frontend/src/components/PlayerInfo.jsx @@ -0,0 +1,27 @@ +// @flow +import { Text } from '@blueprintjs/core'; +import React from 'react'; +import { connect } from 'react-redux'; +import type { Player } from '../models/players'; +import { getCurrentPlayer } from '../redux/players'; + +export type PlayerInfoProps = { + player: ?Player, +} + +const PlayerInfoPresenter = ({player}: PlayerInfoProps) => ( + <Text> + <b>Username:</b> + {' '} + {player && player.displayName} + </Text> +); + +const mapStateToProps = state => ({ + player: getCurrentPlayer(state), +}); + +const mapDispatchToProps = { +}; + +export const PlayerInfo = connect(mapStateToProps, mapDispatchToProps)(PlayerInfoPresenter); diff --git a/frontend/src/components/game-browser/GameBrowser.jsx b/frontend/src/components/game-browser/GameBrowser.jsx new file mode 100644 index 00000000..db0bbb9a --- /dev/null +++ b/frontend/src/components/game-browser/GameBrowser.jsx @@ -0,0 +1,54 @@ +// @flow +import { Button, Classes, InputGroup, Intent } from '@blueprintjs/core'; +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { Flex } from 'reflexbox'; +import { GameList } from './GameList'; +import { PlayerInfo } from '../PlayerInfo'; +import { actions } from '../../redux/games'; + +export type GameBrowserProps = { + createGame: (gameName: string) => void, +} + +class GameBrowserPresenter extends Component<GameBrowserProps> { + + _gameName: string | void = undefined; + + createGame = (e: SyntheticEvent<*>): void => { + e.preventDefault(); + if (this._gameName !== undefined) { + this.props.createGame(this._gameName); + } + }; + + render() { + return ( + <div> + <Flex align="center" justify='space-between' p={1}> + <InputGroup + placeholder="Game name" + name="game_name" + onChange={(e: SyntheticInputEvent<*>) => (this._gameName = e.target.value)} + rightElement={<CreateGameButton onClick={this.createGame}/>} + /> + <PlayerInfo /> + </Flex> + <GameList /> + </div> + ); + } +} + +const CreateGameButton = ({onClick}) => ( + <Button className={Classes.MINIMAL} onClick={onClick} intent={Intent.PRIMARY}>Create Game</Button> +); + +const mapStateToProps = () => ({ +}); + +const mapDispatchToProps = { + createGame: actions.requestCreateGame, +}; + +export const GameBrowser = connect(mapStateToProps, mapDispatchToProps)(GameBrowserPresenter); diff --git a/frontend/src/components/game-browser/GameList.jsx b/frontend/src/components/game-browser/GameList.jsx new file mode 100644 index 00000000..e3601d51 --- /dev/null +++ b/frontend/src/components/game-browser/GameList.jsx @@ -0,0 +1,37 @@ +// @flow +import { Button, Text } from '@blueprintjs/core'; +import type { List } from 'immutable'; +import React from 'react'; +import { connect } from 'react-redux'; +import { Flex } from 'reflexbox'; +import type { Game } from '../../models/games'; +import { actions, getAllGames } from '../../redux/games'; + +type GameListProps = { + games: List<Game>, + joinGame: (gameId: string) => void, +}; + +const GameListPresenter = ({ games, joinGame }: GameListProps) => ( + <div> + {games.map((game: Game, index: number) => { + return ( + <Flex key={game.get('displayName', index)}> + <Text>{game.name}</Text> + <Button onClick={() => joinGame(game.id)}>Join</Button> + </Flex> + ); + })} + </div> +); + +const mapStateToProps = state => ({ + games: getAllGames(state.get('games')), +}); + +const mapDispatchToProps = { + joinGame: actions.requestJoinGame, +}; + +export const GameList = connect(mapStateToProps, mapDispatchToProps)(GameListPresenter); + diff --git a/frontend/src/components/gameList.js b/frontend/src/components/gameList.js deleted file mode 100644 index b8567130..00000000 --- a/frontend/src/components/gameList.js +++ /dev/null @@ -1,19 +0,0 @@ -// @flow -import { Button, Text } from '@blueprintjs/core'; -import type { List } from 'immutable'; -import React from 'react'; -import { Flex } from 'reflexbox'; -import type { Game } from '../models/games'; - -export const GameList = ({ games, joinGame }: { games: List<Game>, joinGame: (gameId: string) => void }) => ( - <div> - {games.map((game: Game, index: number) => { - return ( - <Flex key={game.get('displayName', index)}> - <Text>{game.name}</Text> - <Button onClick={() => joinGame(game.id)}>Join</Button> - </Flex> - ); - })} - </div> -); |