summaryrefslogtreecommitdiff
path: root/frontend/src/components/game-browser/GameList.jsx
blob: e3601d51bbf55d840ec99b76097a9be7226fb3a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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