From 91f2a61a7f5376c742da791523814bb4839b01ee Mon Sep 17 00:00:00 2001 From: Victor Chabbert Date: Sun, 22 Jan 2017 13:45:26 +0100 Subject: Refactor user reducer to player reducer --- frontend/src/redux/players.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 frontend/src/redux/players.js (limited to 'frontend/src/redux/players.js') diff --git a/frontend/src/redux/players.js b/frontend/src/redux/players.js new file mode 100644 index 00000000..e49d4bbf --- /dev/null +++ b/frontend/src/redux/players.js @@ -0,0 +1,36 @@ +import { fromJS } from 'immutable' + +export const types = { + SET_USERNAME: 'USER/SET_USERNAME', + CHOOSE_USERNAME: 'USER/CHOOSE_USERNAME' +} + +export const actions = { + setUsername: (username, displayName, index) => ({ + type: types.SET_USERNAME, + username, + index, + displayName + }), + chooseUsername: (username) => ({ type: types.CHOOSE_USERNAME, username }), +} + + +const initialState = fromJS({ + all: {}, + current: null +}) + +export default (state = initialState, action) => { + switch (action.type) { + case types.SET_USERNAME: + const user = fromJS({ + username: action.username, + displayName: action.displayName, + index: action.index, + }) + return state.setIn(['all', user.get('username')], user).set('current', user.get('username')) + default: + return state + } +} -- cgit