summaryrefslogtreecommitdiff
path: root/frontend/src/components/game-browser/GameList.jsx
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2018-06-09 13:36:45 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2018-06-09 13:36:45 +0200
commit73389ad516af4cb49873cc19c2dc65efc77d6eb8 (patch)
tree85ecfb9b15c1db0b01300e7b18b0d7ad2d1a2d76 /frontend/src/components/game-browser/GameList.jsx
parentFix frontend gitignore (diff)
downloadseven-wonders-73389ad516af4cb49873cc19c2dc65efc77d6eb8.tar.gz
seven-wonders-73389ad516af4cb49873cc19c2dc65efc77d6eb8.tar.bz2
seven-wonders-73389ad516af4cb49873cc19c2dc65efc77d6eb8.zip
Split GameBrowser into multiple connected components
Diffstat (limited to 'frontend/src/components/game-browser/GameList.jsx')
-rw-r--r--frontend/src/components/game-browser/GameList.jsx37
1 files changed, 37 insertions, 0 deletions
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);
+
bgstack15