From 10646b1fe23b89a139e9e013ddf047b5fc11b99f Mon Sep 17 00:00:00 2001 From: jbion Date: Sat, 23 Feb 2019 05:03:31 +0100 Subject: Improve GameScene by showing the hand --- frontend/src/redux/currentGame.js | 55 ++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 24 deletions(-) (limited to 'frontend/src/redux') 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 = 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; } }; -- cgit