summaryrefslogtreecommitdiff
path: root/frontend/src/redux/games.js
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-05-11 19:47:49 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2017-05-12 00:13:57 +0200
commitb494d2d141a942b0905ac46a551ff42878f0f081 (patch)
tree18d94a3e86d0749f013075a110d6c43efaa782de /frontend/src/redux/games.js
parentAdd time limit setting (diff)
downloadseven-wonders-b494d2d141a942b0905ac46a551ff42878f0f081.tar.gz
seven-wonders-b494d2d141a942b0905ac46a551ff42878f0f081.tar.bz2
seven-wonders-b494d2d141a942b0905ac46a551ff42878f0f081.zip
First attempt at lobby joining
Diffstat (limited to 'frontend/src/redux/games.js')
-rw-r--r--frontend/src/redux/games.js38
1 files changed, 24 insertions, 14 deletions
diff --git a/frontend/src/redux/games.js b/frontend/src/redux/games.js
index 4115323c..5ad6f8d2 100644
--- a/frontend/src/redux/games.js
+++ b/frontend/src/redux/games.js
@@ -1,29 +1,39 @@
-import { Map } from 'immutable'
+import {fromJS} from 'immutable'
export const types = {
- CREATE_OR_UPDATE_GAMES: 'GAME/CREATE_OR_UPDATE_GAMES',
- ENTER_GAME: 'GAME/ENTER_GAME',
- JOIN_GAME: 'GAME/JOIN_GAME',
- CREATE_GAME: 'GAME/CREATE_GAME',
+ UPDATE_GAMES: 'GAME/UPDATE_GAMES',
+ REQUEST_CREATE_GAME: 'GAME/REQUEST_CREATE_GAME',
+ REQUEST_JOIN_GAME: 'GAME/REQUEST_JOIN_GAME',
+ ENTER_LOBBY: 'GAME/ENTER_LOBBY',
}
export const actions = {
- createOrUpdateGame: (games) => ({ type: types.CREATE_OR_UPDATE_GAMES, games }),
- enterGame: (username) => ({ type: types.ENTER_GAME, username }),
- joinGame: (id) => ({ type: types.JOIN_GAME, id }),
- createGame: (name) => ({ type: types.CREATE_GAME, name }),
+ updateGames: (games) => ({ type: types.UPDATE_GAMES, games }),
+ requestJoinGame: (id) => ({ type: types.REQUEST_JOIN_GAME, id }),
+ requestCreateGame: (name) => ({ type: types.REQUEST_CREATE_GAME, name }),
+ enterLobby: (lobby) => ({ type: types.ENTER_LOBBY, lobby }),
}
-
-const initialState = Map({})
+const initialState = fromJS({
+ all: {},
+ current: ''
+})
export default (state = initialState, action) => {
switch (action.type) {
- case types.CREATE_OR_UPDATE_GAMES:
- return state.mergeDeep(action.games)
+ case types.UPDATE_GAMES:
+ return state.setIn(['all'], state.get('all').mergeDeep(action.games))
+ case types.ENTER_LOBBY:
+ return state.set('current', action.lobby.get('id'))
default:
return state
}
}
-export const getAllGames = state => state.get('games')
+const getState = globalState => globalState.get('games')
+
+export const getAllGamesById = globalState => getState(globalState).get('all')
+export const getAllGames = globalState => getAllGamesById(globalState).toList()
+export const getGame = (globalState, id) => getAllGamesById(globalState).get(id)
+export const getCurrentGameId = globalState => getState(globalState).get('current')
+export const getCurrentGame = globalState => getGame(globalState, getCurrentGameId(globalState))
bgstack15