summaryrefslogtreecommitdiff
path: root/frontend/src/scenes/GameBrowser
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2018-04-29 21:10:55 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2018-04-29 21:51:10 +0200
commit73ede6097d5fcd871522a87d02a0c5bc9db00464 (patch)
tree67cf69bcdd3556f73aaa419ac9a367a6fcb0b000 /frontend/src/scenes/GameBrowser
parentCleanup index.js files (diff)
downloadseven-wonders-73ede6097d5fcd871522a87d02a0c5bc9db00464.tar.gz
seven-wonders-73ede6097d5fcd871522a87d02a0c5bc9db00464.tar.bz2
seven-wonders-73ede6097d5fcd871522a87d02a0c5bc9db00464.zip
Remove default exports everywhere
Diffstat (limited to 'frontend/src/scenes/GameBrowser')
-rw-r--r--frontend/src/scenes/GameBrowser/index.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/frontend/src/scenes/GameBrowser/index.js b/frontend/src/scenes/GameBrowser/index.js
new file mode 100644
index 00000000..20a835d1
--- /dev/null
+++ b/frontend/src/scenes/GameBrowser/index.js
@@ -0,0 +1,65 @@
+// @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<Game>,
+ 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 (
+ <div>
+ <Flex align="center" p={1}>
+ <InlineForm
+ buttonLabel="Create Game"
+ label="Game name"
+ name="game_name"
+ onChange={(e: SyntheticInputEvent) => (this._gameName = e.target.value)}
+ onClick={this.createGame}
+ />
+ <Space auto />
+ <Text>
+ <b>Username:</b>
+ {' '}
+ {this.props.currentPlayer && this.props.currentPlayer.displayName}
+ </Text>
+ <Space x={1} />
+ </Flex>
+ <GameList games={this.props.games} joinGame={this.props.joinGame} />
+ </div>
+ );
+ }
+}
+
+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);
bgstack15