diff options
Diffstat (limited to 'frontend/src/redux')
-rw-r--r-- | frontend/src/redux/currentGame.js | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/frontend/src/redux/currentGame.js b/frontend/src/redux/currentGame.js index cefabb6f..f4174eca 100644 --- a/frontend/src/redux/currentGame.js +++ b/frontend/src/redux/currentGame.js @@ -1,32 +1,39 @@ // @flow -import type { ApiPlayerTurnInfo } from '../api/model'; +import { List } from 'immutable'; +import { combineReducers } from 'redux'; +import type { ApiPlayerTurnInfo, ApiTable } from '../api/model'; import { CurrentGameState } from '../models/currentGame'; import type { Action } from './actions/all'; import { types } from './actions/game'; -export const currentGameReducer = (state: CurrentGameState = new CurrentGameState(), action: Action) => { - switch (action.type) { - case types.REQUEST_SAY_READY: - // TODO handle end of feedback between say ready and ready event received - return state; - case types.PLAYER_READY_RECEIVED: - // const newReadiness = state.playersReadiness.set(action.username, true); - // return { playersReadiness: newReadiness, ...state }; - return state; - case types.TABLE_UPDATE_RECEIVED: - // TODO - return state; - case types.PREPARED_CARD_RECEIVED: - // TODO - return state; - case types.TURN_INFO_RECEIVED: - // TODO find a better way to just update what's needed - const newState = new CurrentGameState(); - newState.turnInfo = action.turnInfo; - newState.playersReadiness = state.playersReadiness; - return newState; - default: - return state; +export function createCurrentGameReducer() { + return combineReducers({ + readyUsernames: readyUsernamesReducer, + turnInfo: turnInfoReducer, + }); +} + +const readyUsernamesReducer = (state: List<string> = new List(), action: Action) => { + if (action.type === types.PLAYER_READY_RECEIVED) { + return state.push(action.username); + } else { + return state; + } +}; + +const turnInfoReducer = (state: ApiPlayerTurnInfo | null = null, action: Action) => { + if (action.type === types.TURN_INFO_RECEIVED) { + return action.turnInfo; + } else { + return state; + } +}; + +const tableUpdatesReducer = (state: ApiTable, action: Action) => { + if (action.type === types.TABLE_UPDATE_RECEIVED) { + return action.table; + } else { + return state; } }; |