2016-06-23 20:05:30 -07:00
|
|
|
import types from './types';
|
2016-06-20 11:35:19 -07:00
|
|
|
|
2016-08-08 16:21:04 -07:00
|
|
|
const { updateUserPoints } = types;
|
2016-03-10 17:21:46 -08:00
|
|
|
const initialState = {
|
2016-05-09 13:42:39 -07:00
|
|
|
superBlock: {},
|
|
|
|
block: {},
|
2016-03-10 17:21:46 -08:00
|
|
|
challenge: {},
|
2016-06-20 11:35:19 -07:00
|
|
|
user: {}
|
2016-03-10 17:21:46 -08:00
|
|
|
};
|
|
|
|
|
2016-07-19 16:36:34 -07:00
|
|
|
// future refactor(berks): Several of the actions here are just updating props
|
|
|
|
// on the main user. These can be refactors into one response for all actions
|
2016-05-09 13:42:39 -07:00
|
|
|
export default function entities(state = initialState, action) {
|
2016-07-19 16:36:34 -07:00
|
|
|
const {
|
|
|
|
type,
|
|
|
|
payload: { email, username, points, flag, languageTag } = {}
|
|
|
|
} = action;
|
|
|
|
if (action.meta && action.meta.entities) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...action.meta.entities
|
|
|
|
};
|
|
|
|
}
|
2016-06-20 11:35:19 -07:00
|
|
|
if (type === updateUserPoints) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
user: {
|
|
|
|
...state.user,
|
|
|
|
[username]: {
|
|
|
|
...state.user[username],
|
|
|
|
points
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2016-07-19 16:36:34 -07:00
|
|
|
if (action.type === types.updateUserFlag) {
|
2016-03-10 17:21:46 -08:00
|
|
|
return {
|
|
|
|
...state,
|
2016-07-19 16:36:34 -07:00
|
|
|
user: {
|
|
|
|
...state.user,
|
|
|
|
[username]: {
|
|
|
|
...state.user[username],
|
|
|
|
[flag]: !state.user[username][flag]
|
|
|
|
}
|
|
|
|
}
|
2016-03-10 17:21:46 -08:00
|
|
|
};
|
|
|
|
}
|
2016-07-19 16:36:34 -07:00
|
|
|
if (action.type === types.updateUserEmail) {
|
2016-07-16 10:38:06 -07:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
user: {
|
|
|
|
...state.user,
|
|
|
|
[username]: {
|
|
|
|
...state.user[username],
|
2016-07-19 16:36:34 -07:00
|
|
|
email
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === types.updateUserLang) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
user: {
|
|
|
|
...state.user,
|
|
|
|
[username]: {
|
|
|
|
...state.user[username],
|
|
|
|
languageTag
|
2016-07-16 10:38:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2016-08-03 15:26:05 -07:00
|
|
|
|
|
|
|
if (action.type === types.updateMyCurrentChallenge) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
user: {
|
|
|
|
...state.user,
|
|
|
|
[username]: {
|
|
|
|
...state.user[username],
|
|
|
|
currentChallengeId: action.payload.currentChallengeId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2016-08-11 16:41:03 -07:00
|
|
|
|
|
|
|
if (action.type === types.updateUserChallenge) {
|
|
|
|
const { challengeInfo } = action.payload;
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
user: {
|
|
|
|
...state.user,
|
|
|
|
[username]: {
|
|
|
|
...state.user[username],
|
|
|
|
challengeMap: {
|
|
|
|
...state.user[username].challengeMap,
|
|
|
|
[challengeInfo.id]: challengeInfo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2016-03-10 17:21:46 -08:00
|
|
|
return state;
|
|
|
|
}
|