diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2019-05-05 20:38:49 +0200 |
---|---|---|
committer | jbion <joffrey.bion@amadeus.com> | 2019-05-06 18:33:15 +0200 |
commit | fb32eee5caf331097e69d89af94767bbdca6abba (patch) | |
tree | 6a81d78f79889e80519f991ccd82844da401653c /frontend/src/components/lobby/Lobby.tsx | |
parent | Migrate radial-maths components to TypeScript (diff) | |
download | seven-wonders-fb32eee5caf331097e69d89af94767bbdca6abba.tar.gz seven-wonders-fb32eee5caf331097e69d89af94767bbdca6abba.tar.bz2 seven-wonders-fb32eee5caf331097e69d89af94767bbdca6abba.zip |
Migrate lobby components to TypeScript
Diffstat (limited to 'frontend/src/components/lobby/Lobby.tsx')
-rw-r--r-- | frontend/src/components/lobby/Lobby.tsx | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/frontend/src/components/lobby/Lobby.tsx b/frontend/src/components/lobby/Lobby.tsx new file mode 100644 index 00000000..3594af65 --- /dev/null +++ b/frontend/src/components/lobby/Lobby.tsx @@ -0,0 +1,56 @@ +import { Button, Classes, Intent } from '@blueprintjs/core'; +import { List } from 'immutable'; +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { ApiLobby, ApiPlayer } from '../../api/model'; +import { GlobalState } from '../../reducers'; +import { actions } from '../../redux/actions/lobby'; +import { getCurrentGame } from '../../redux/games'; +import { getCurrentPlayer } from '../../redux/user'; +import { RadialPlayerList } from './RadialPlayerList'; + +export type LobbyStateProps = { + currentGame: ApiLobby | null, + currentPlayer: ApiPlayer | null, + players: List<ApiPlayer>, +} + +export type LobbyDispatchProps = { + startGame: () => void, +} + +export type LobbyProps = LobbyStateProps & LobbyDispatchProps + +class LobbyPresenter extends Component<LobbyProps> { + + render() { + const {currentGame, currentPlayer, players, startGame} = this.props; + if (!currentGame || !currentPlayer) { + return <div>Error: no current game.</div> + } + return ( + <div> + <h2>{currentGame.name + ' — Lobby'}</h2> + <RadialPlayerList players={players}/> + {currentPlayer.gameOwner && <Button text="START" className={Classes.LARGE} intent={Intent.PRIMARY} icon='play' + onClick={startGame} disabled={players.size < 3}/>} + </div> + ); + } +} + +function mapStateToProps(state: GlobalState): LobbyStateProps { + const game = getCurrentGame(state); + console.info(game); + return { + currentGame: game, + currentPlayer: getCurrentPlayer(state), + players: game ? List(game.players) : List(), + }; +} + +const mapDispatchToProps = { + startGame: actions.requestStartGame, +}; + +export const Lobby = connect(mapStateToProps, mapDispatchToProps)(LobbyPresenter); |