-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera-roll.js
165 lines (154 loc) · 3.54 KB
/
camera-roll.js
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* Camera Roll Reducer
*/
import * as ActionTypes from '../actions/action-types';
const initialSaveState = {
inProgress: false,
success: false,
error: null,
};
const initialLoadState = {
loading: false,
loaded: false,
error: null,
};
const initialParamsState = {
first: 6,
assetType: 'Photos',
// groupTypes: 'All',
};
const initialGetPhotosState = {
...initialLoadState,
edges: [],
params: {
...initialParamsState,
},
initParams: {
...initialParamsState,
},
loadMore: {
hasMore: true,
...initialLoadState,
},
};
const initialState = {
ACTION: 'init',
mediaItem: null,
save: {
...initialSaveState,
},
photos: {
...initialGetPhotosState,
},
};
export default function cameraRoll(state = initialState, action = {}) {
const { payload } = action;
switch (action.type) {
/*
* Get Photos
*/
case ActionTypes.CAMERA_ROLL_GET_PHOTOS_INIT: {
return {
...state,
ACTION: ActionTypes.CAMERA_ROLL_GET_PHOTOS_INIT,
photos: {
...initialGetPhotosState,
},
};
}
case ActionTypes.CAMERA_ROLL_GET_PHOTOS_START: {
return {
...state,
ACTION: ActionTypes.CAMERA_ROLL_GET_PHOTOS_START,
photos: {
...state.photos,
loading: true,
},
};
}
case ActionTypes.CAMERA_ROLL_GET_PHOTOS_SUCCESS: {
return {
...state,
ACTION: ActionTypes.CAMERA_ROLL_GET_PHOTOS_SUCCESS,
photos: {
...state.photos,
...payload.photos,
edges: [...state.photos.edges, ...payload.photos.edges],
params: {
...state.photos.params,
after: payload.photos.pageInfo.endCursor,
},
loadMore: {
...state.photos.loadMore,
hasMore: payload.photos.pageInfo.hasNextPage,
},
loading: false,
loaded: true,
},
};
}
case ActionTypes.CAMERA_ROLL_GET_PHOTOS_FAILURE: {
return {
...state,
ACTION: ActionTypes.CAMERA_ROLL_GET_PHOTOS_FAILURE,
photos: {
...state.photos,
loading: false,
error: payload.error,
},
};
}
/*
* Get More Photos
*/
case ActionTypes.CAMERA_ROLL_GET_MORE_PHOTOS_START: {
return {
...state,
ACTION: ActionTypes.CAMERA_ROLL_GET_MORE_PHOTOS_START,
photos: {
...state.photos,
loadMore: {
...state.photos.loadMore,
loading: true,
},
},
};
}
case ActionTypes.CAMERA_ROLL_GET_MORE_PHOTOS_SUCCESS: {
return {
...state,
ACTION: ActionTypes.CAMERA_ROLL_GET_MORE_PHOTOS_SUCCESS,
photos: {
...state.photos,
...payload.photos,
edges: [...state.photos.edges, ...payload.photos.edges],
params: {
...state.photos.params,
after: payload.photos.pageInfo.endCursor,
},
loadMore: {
...state.photos.loadMore,
hasMore: payload.photos.pageInfo.hasNextPage,
loading: false,
loaded: true,
},
},
};
}
case ActionTypes.CAMERA_ROLL_GET_MORE_PHOTOS_FAILURE: {
return {
...state,
ACTION: ActionTypes.CAMERA_ROLL_GET_MORE_PHOTOS_FAILURE,
photos: {
...state.photos,
loadMore: {
...state.photos.loadMore,
loading: false,
error: payload.error,
},
},
};
}
}
return state;
}