forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhome.js
More file actions
48 lines (41 loc) · 982 Bytes
/
home.js
File metadata and controls
48 lines (41 loc) · 982 Bytes
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
import * as types from '../constants/ActionTypes';
import * as TABS from '../constants/Tabs';
const tabs = TABS.tabs;
let initialState = {};
tabs.forEach((item)=> {
initialState[item] = {
pullRefreshPending: false,
reachedEndPending: false,
page: 1,
limit: 10,
flag: 0
}
});
export default function (state = initialState, action) {
const {payload, error, meta={}, type} = action;
const {sequence={}, tab} = meta;
const pending = sequence.type === 'start';
switch (type) {
case types.GET_TOPICS_BY_TAB:
return {
...state,
[tab]: {
...state[tab],
reachedEndPending: pending,
page: (!error && !pending) ? state[tab].page + 1: state[tab].page
}
};
case types.UPDATE_TOPICS_BY_TAB:
return {
...state,
[tab]: {
...state[tab],
pullRefreshPending: pending,
page: initialState[tab].page,
flag: (!error && !pending) ? state[tab].flag + 1 : state[tab].flag
}
};
default:
return state;
}
}