userReducer.js
3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'use strict'
import InitialState from './userInitialState';
import Immutable, {List, Record} from 'immutable';
const {
USER_BACKGROUND_TAP,
USER_POSTS_REQUEST,
USER_POSTS_SUCCESS,
USER_POSTS_FAILURE,
USER_LIKE_REQUEST,
USER_LIKE_SUCCESS,
USER_LIKE_FAILURE,
USER_REPLY_REQUEST,
USER_REPLY_SUCCESS,
USER_REPLY_FAILURE,
USER_GO_TO_SETTING_STATS,
SYNC_USER_REQUEST,
SYNC_USER_SUCCESS,
SYNC_USER_FAILURE,
GET_USER_INFO_REQUEST,
GET_USER_INFO_SUCCESS,
GET_USER_INFO_FAILURE,
SET_UID,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function user(state = initialState, action) {
if (!(state instanceof InitialState)) {
return initialState.merge(state);
}
switch (action.type) {
case USER_BACKGROUND_TAP:
{
// let nextState = state.set
}
break;
case USER_POSTS_REQUEST: {
let nextState = state.set('isFetching', true).set('error', null);
return nextState;
}
case USER_POSTS_SUCCESS:
{
// let nextState = state.set
let posts = state.posts;
let jsonData = posts.jsonData;
let origin = jsonData.toJS();
let {list} = action.payload;
let data = [...origin, ...(list || [])];
let nextState = state.set('isFetching', false)
.setIn(['posts','jsonData'], Immutable.fromJS(data));
return nextState;
}
break;
case USER_POSTS_FAILURE: {
let nextState = state.set('isFetching',false)
.set('error', action.playload);
return nextState;
}
case USER_GO_TO_SETTING_STATS:
return state;
case SYNC_USER_REQUEST: {
let nextState = state.setIn(['profile', 'isFetching'], true)
.setIn(['profile', 'error'], null);
return nextState;
}
case SYNC_USER_SUCCESS: {
let {avatar, bgImage, nickName, realName, gender, sign, age, birthday, height, weight, msgCount} = action.payload;
let nextState = state.setIn(['profile', 'isFetching'], false)
.setIn(['profile', 'error'], null)
.setIn(['profile', 'avatar'], avatar)
.setIn(['profile', 'bgImage'], bgImage)
.setIn(['profile', 'nickName'], nickName)
.setIn(['profile', 'realName'], realName)
.setIn(['profile', 'gender'], gender)
.setIn(['profile', 'sign'], sign)
.setIn(['profile', 'age'], age)
.setIn(['profile', 'birthday'], birthday)
.setIn(['profile', 'height'], height)
.setIn(['profile', 'weight'], weight)
.setIn(['profile', 'msgCount'], msgCount);
return nextState;
}
case SYNC_USER_FAILURE: {
let nextState = state.setIn(['profile', 'isFetching'], false)
.setIn(['profile', 'error'], action.payload);
return nextState;
}
case SET_UID:
return state.setIn(['profile', 'uid'], action.payload);
}
return state;
}