summaryrefslogtreecommitdiff
path: root/frontend/src/components/game-browser/GameBrowser.jsx
blob: db0bbb9af221c41a5cc0f8d5afb9269744d9afe6 (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
52
53
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);
bgstack15