summaryrefslogtreecommitdiff
path: root/frontend/src/redux/games.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/redux/games.js')
-rw-r--r--frontend/src/redux/games.js42
1 files changed, 5 insertions, 37 deletions
diff --git a/frontend/src/redux/games.js b/frontend/src/redux/games.js
index ee8b13df..68571981 100644
--- a/frontend/src/redux/games.js
+++ b/frontend/src/redux/games.js
@@ -1,48 +1,16 @@
// @flow
import type { List, Map } from 'immutable';
-import { fromJS } from 'immutable';
-import type { Game, GameMapType, GameNormalMapType, GameShape } from '../models/games';
+import type { Game } from '../models/games';
import { GamesState } from '../models/games';
+import type { Action } from './actions/all';
+import { types } from './actions/lobby';
-export const types = {
- UPDATE_GAMES: 'GAMES/UPDATE_GAMES',
- REQUEST_CREATE_GAME: 'GAMES/REQUEST_CREATE_GAME',
- REQUEST_JOIN_GAME: 'GAMES/REQUEST_JOIN_GAME',
- REQUEST_START_GAME: 'GAMES/REQUEST_START_GAME',
- ENTER_LOBBY: 'GAMES/ENTER_LOBBY',
- ENTER_GAME: 'GAMES/ENTER_GAME',
-};
-
-export type UpdateGamesAction = { type: 'GAMES/UPDATE_GAMES', games: GameMapType };
-export type RequestCreateGameAction = { type: 'GAMES/REQUEST_CREATE_GAME', gameName: string };
-export type RequestJoinGameAction = { type: 'GAMES/REQUEST_JOIN_GAME', gameId: string };
-export type RequestStartGameAction = { type: 'GAMES/REQUEST_START_GAME' };
-export type EnterLobbyAction = { type: 'GAMES/ENTER_LOBBY', lobby: GameShape };
-export type EnterGameAction = { type: 'GAMES/ENTER_GAME' };
-
-export type GamesAction =
- | UpdateGamesAction
- | RequestCreateGameAction
- | RequestJoinGameAction
- | RequestStartGameAction
- | EnterLobbyAction
- | EnterGameAction;
-
-export const actions = {
- updateGames: (games: GameNormalMapType): UpdateGamesAction => ({ type: types.UPDATE_GAMES, games: fromJS(games) }),
- requestJoinGame: (gameId: string): RequestJoinGameAction => ({ type: types.REQUEST_JOIN_GAME, gameId }),
- requestCreateGame: (gameName: string): RequestCreateGameAction => ({ type: types.REQUEST_CREATE_GAME, gameName }),
- requestStartGame: (): RequestStartGameAction => ({ type: types.REQUEST_START_GAME }),
- enterLobby: (lobby: GameShape): EnterLobbyAction => ({ type: types.ENTER_LOBBY, lobby: fromJS(lobby) }),
- enterGame: (): EnterGameAction => ({ type: types.ENTER_GAME }),
-};
-
-export const gamesReducer = (state: GamesState = new GamesState(), action: GamesAction) => {
+export const gamesReducer = (state: GamesState = new GamesState(), action: Action) => {
switch (action.type) {
case types.UPDATE_GAMES:
return state.addGames(action.games);
case types.ENTER_LOBBY:
- return state.set('current', action.lobby.get('id'));
+ return state.set('current', action.gameId);
default:
return state;
}
bgstack15