summaryrefslogtreecommitdiff
path: root/frontend/src/scenes/Lobby/index.js
blob: 0a427805512b1c0f18c653899956baccba20e1b6 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//@flow
import { Button } from '@blueprintjs/core';
import { List } from 'immutable';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { PlayerList } from '../../components/playerList';
import type { Game } from '../../models/games';
import type { Player } from '../../models/players';
import { actions, getCurrentGame } from '../../redux/games';
import { getPlayers } from '../../redux/players';

export type LobbyProps = {
  currentGame: Game,
  players: List<Player>,
  startGame: () => void,
}

class LobbyPresenter extends Component<LobbyProps> {
  getTitle() {
    if (this.props.currentGame) {
      return this.props.currentGame.name + ' — Lobby';
    } else {
      return 'What are you doing here? You haven\'t joined a game yet!';
    }
  }

  render() {
    return (
      <div>
        <h2>{this.getTitle()}</h2>
        <PlayerList players={this.props.players} />
        <Button onClick={this.props.startGame}>Start Game</Button>
      </div>
    );
  }
}

const mapStateToProps = state => {
  const game = getCurrentGame(state.get('games'));
  console.info(game);
  return {
    currentGame: game,
    players: game ? getPlayers(state.get('players'), game.players) : new List(),
  };
};

const mapDispatchToProps = {
  startGame: actions.requestStartGame,
};

export const Lobby = connect(mapStateToProps, mapDispatchToProps)(LobbyPresenter);
bgstack15