From bd212b997b2c7293f98db6a6be2b2900da87af6f Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Sun, 10 Jun 2018 15:41:42 +0200 Subject: Finish moving components out of /scenes package --- frontend/src/components/lobby/Lobby.jsx | 51 ++++++++++++++++++++++++++++ frontend/src/components/lobby/PlayerList.jsx | 23 +++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 frontend/src/components/lobby/Lobby.jsx create mode 100644 frontend/src/components/lobby/PlayerList.jsx (limited to 'frontend/src/components/lobby') diff --git a/frontend/src/components/lobby/Lobby.jsx b/frontend/src/components/lobby/Lobby.jsx new file mode 100644 index 00000000..ea865025 --- /dev/null +++ b/frontend/src/components/lobby/Lobby.jsx @@ -0,0 +1,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/lobby/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, + startGame: () => void, +} + +class LobbyPresenter extends Component { + 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 ( +
+

{this.getTitle()}

+ + +
+ ); + } +} + +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); diff --git a/frontend/src/components/lobby/PlayerList.jsx b/frontend/src/components/lobby/PlayerList.jsx new file mode 100644 index 00000000..db3d4418 --- /dev/null +++ b/frontend/src/components/lobby/PlayerList.jsx @@ -0,0 +1,23 @@ +//@flow +import { Text } from '@blueprintjs/core'; +import { List } from 'immutable'; +import React from 'react'; +import { Flex } from 'reflexbox'; +import { Player } from '../../models/players'; + +type PlayerListProps = { + players: List; +}; + +const PlayerItem = ({player}) => ( + + {player.displayName} + ({player.username}) + +); + +export const PlayerList = ({players}: PlayerListProps) => ( +
+ {players.map(player => )} +
+); -- cgit