summaryrefslogtreecommitdiff
path: root/frontend/src/scenes
diff options
context:
space:
mode:
authorVictor Chabbert <chabbertvi@eisti.eu>2017-07-31 18:44:01 +0200
committerVictor Chabbert <chabbertvi@eisti.eu>2017-08-07 22:41:20 +0200
commitbe86c9d23cdae888598e1f7de7812d7e0f1ca12c (patch)
treef39e95e3e8781c336b6221ce91c557d9e7e84fb0 /frontend/src/scenes
parentUpdrade react router and react router redux (diff)
downloadseven-wonders-be86c9d23cdae888598e1f7de7812d7e0f1ca12c.tar.gz
seven-wonders-be86c9d23cdae888598e1f7de7812d7e0f1ca12c.tar.bz2
seven-wonders-be86c9d23cdae888598e1f7de7812d7e0f1ca12c.zip
Refactor routes to new structure
Diffstat (limited to 'frontend/src/scenes')
-rw-r--r--frontend/src/scenes/Games/index.js65
-rw-r--r--frontend/src/scenes/Lobby/index.js42
-rw-r--r--frontend/src/scenes/SplashScreen/components/HomeLayout.js17
-rw-r--r--frontend/src/scenes/SplashScreen/components/background-zeus-temple.jpgbin0 -> 571089 bytes
-rw-r--r--frontend/src/scenes/SplashScreen/components/logo-7-wonders.pngbin0 -> 301442 bytes
-rw-r--r--frontend/src/scenes/SplashScreen/index.js42
-rw-r--r--frontend/src/scenes/index.js17
7 files changed, 183 insertions, 0 deletions
diff --git a/frontend/src/scenes/Games/index.js b/frontend/src/scenes/Games/index.js
new file mode 100644
index 00000000..a2031030
--- /dev/null
+++ b/frontend/src/scenes/Games/index.js
@@ -0,0 +1,65 @@
+// @flow
+import type { List } from 'immutable';
+import React, { Component } from 'react';
+import { connect } from 'react-redux';
+import { InlineForm, Space, Text } from 'rebass';
+import { Flex } from 'reflexbox';
+import GameList from '../../components/gameList';
+import type { Games } from '../../models/games';
+import type { Player } from '../../models/players';
+import { actions, getAllGames } from '../../redux/games';
+import { getCurrentPlayer } from '../../redux/players';
+
+class GameBrowser extends Component {
+ props: {
+ currentPlayer: Player,
+ games: List<Games>,
+ createGame: (gameName: string) => void,
+ joinGame: (gameId: string) => void
+ };
+
+ _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" p={1}>
+ <InlineForm
+ buttonLabel="Create Game"
+ label="Game name"
+ name="game_name"
+ onChange={(e: SyntheticInputEvent) => (this._gameName = e.target.value)}
+ onClick={this.createGame}
+ />
+ <Space auto />
+ <Text>
+ <b>Username:</b>
+ {' '}
+ {this.props.currentPlayer && this.props.currentPlayer.displayName}
+ </Text>
+ <Space x={1} />
+ </Flex>
+ <GameList games={this.props.games} joinGame={this.props.joinGame} />
+ </div>
+ );
+ }
+}
+
+const mapStateToProps = state => ({
+ currentPlayer: getCurrentPlayer(state.get('players')),
+ games: getAllGames(state.get('games')),
+});
+
+const mapDispatchToProps = {
+ createGame: actions.requestCreateGame,
+ joinGame: actions.requestJoinGame,
+};
+
+export default connect(mapStateToProps, mapDispatchToProps)(GameBrowser);
diff --git a/frontend/src/scenes/Lobby/index.js b/frontend/src/scenes/Lobby/index.js
new file mode 100644
index 00000000..1b5a11ff
--- /dev/null
+++ b/frontend/src/scenes/Lobby/index.js
@@ -0,0 +1,42 @@
+import { List } from 'immutable';
+import React, { Component } from 'react';
+import { connect } from 'react-redux';
+import { Button } from 'rebass';
+import PlayerList from '../../components/playerList';
+import { actions, getCurrentGame } from '../../redux/games';
+import { getPlayers } from '../../redux/players';
+
+class Lobby 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 (
+ <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 default connect(mapStateToProps, mapDispatchToProps)(Lobby);
diff --git a/frontend/src/scenes/SplashScreen/components/HomeLayout.js b/frontend/src/scenes/SplashScreen/components/HomeLayout.js
new file mode 100644
index 00000000..86666eb2
--- /dev/null
+++ b/frontend/src/scenes/SplashScreen/components/HomeLayout.js
@@ -0,0 +1,17 @@
+// @flow
+import type { Children } from 'react';
+import React from 'react';
+import { Banner } from 'rebass';
+import ErrorToastContainer from '../../../components/errors/errorToastContainer';
+import background from './background-zeus-temple.jpg';
+import logo from './logo-7-wonders.png';
+
+export default ({ children }: { children: Children }) => (
+ <div>
+ <Banner align="center" backgroundImage={background}>
+ <img src={logo} alt="Seven Wonders" />
+ {children}
+ </Banner>
+ <ErrorToastContainer />
+ </div>
+);
diff --git a/frontend/src/scenes/SplashScreen/components/background-zeus-temple.jpg b/frontend/src/scenes/SplashScreen/components/background-zeus-temple.jpg
new file mode 100644
index 00000000..5a28e933
--- /dev/null
+++ b/frontend/src/scenes/SplashScreen/components/background-zeus-temple.jpg
Binary files differ
diff --git a/frontend/src/scenes/SplashScreen/components/logo-7-wonders.png b/frontend/src/scenes/SplashScreen/components/logo-7-wonders.png
new file mode 100644
index 00000000..96974d3e
--- /dev/null
+++ b/frontend/src/scenes/SplashScreen/components/logo-7-wonders.png
Binary files differ
diff --git a/frontend/src/scenes/SplashScreen/index.js b/frontend/src/scenes/SplashScreen/index.js
new file mode 100644
index 00000000..0732b1b3
--- /dev/null
+++ b/frontend/src/scenes/SplashScreen/index.js
@@ -0,0 +1,42 @@
+import React, { Component } from 'react';
+import { connect } from 'react-redux';
+import { Button, Container, Input } from 'rebass';
+import { actions } from '../../redux/players';
+
+import HomeLayout from './components/HomeLayout';
+
+class SplashScreen extends Component {
+ play = e => {
+ e.preventDefault();
+ if (this._username !== undefined) {
+ this.props.chooseUsername(this._username);
+ }
+ };
+
+ render() {
+ return (
+ <HomeLayout>
+ <Container>
+ <Input
+ name="username"
+ label="Username"
+ placeholder="Username"
+ hideLabel
+ onChange={e => (this._username = e.target.value)}
+ />
+ <Button backgroundColor="primary" color="white" big onClick={this.play}>
+ PLAY NOW!
+ </Button>
+ </Container>
+ </HomeLayout>
+ );
+ }
+}
+
+const mapStateToProps = state => ({});
+
+const mapDispatchToProps = {
+ chooseUsername: actions.chooseUsername,
+};
+
+export default connect(mapStateToProps, mapDispatchToProps)(SplashScreen);
diff --git a/frontend/src/scenes/index.js b/frontend/src/scenes/index.js
new file mode 100644
index 00000000..83554d48
--- /dev/null
+++ b/frontend/src/scenes/index.js
@@ -0,0 +1,17 @@
+import React from 'react';
+import { Route, Redirect, Switch } from 'react-router-dom';
+
+import SplashScreen from './SplashScreen';
+import Games from './Games';
+import Lobby from './Lobby';
+
+const Application = () => (
+ <Switch>
+ <Route path="/splash-screen" component={SplashScreen} />
+ <Route path="/games" component={Games} />
+ <Route path="/lobby" component={Lobby} />
+ <Redirect from="*" to="/splash-screen" />
+ </Switch>
+);
+
+export default Application;
bgstack15