-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera-roll.js
86 lines (74 loc) · 1.95 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
/*
* Camera Roll Actions
*/
import { CameraRoll } from 'react-native';
import * as ActionTypes from './action-types';
import ActionDispatcher from './action-dispatcher';
import camelcaseKeys from 'camelcase-keys-deep';
/*
* getPhotos
* @Description: get photos from camera roll
*/
export function getPhotos(options) {
return async dispatch => {
const dispatcher = new ActionDispatcher(dispatch);
try {
dispatcher.dispatch(ActionTypes.CAMERA_ROLL_GET_PHOTOS_START);
const photos = await CameraRoll.getPhotos(options);
dispatcher.dispatch(ActionTypes.CAMERA_ROLL_GET_PHOTOS_SUCCESS, {
photos: camelcaseKeys(photos),
});
} catch (error) {
console.warn('getPhotos : Error');
console.log(error);
dispatcher.dispatch(ActionTypes.CAMERA_ROLL_GET_PHOTOS_FAILURE, {
error,
});
}
};
}
/*
* getMorePhotos
* @Description: get more photos from camera roll
*/
export function getMorePhotos(options) {
return async dispatch => {
const dispatcher = new ActionDispatcher(dispatch);
try {
dispatcher.dispatch(ActionTypes.CAMERA_ROLL_GET_MORE_PHOTOS_START);
const photos = await CameraRoll.getPhotos(options);
dispatcher.dispatch(ActionTypes.CAMERA_ROLL_GET_MORE_PHOTOS_SUCCESS, {
photos: camelcaseKeys(photos),
});
} catch (error) {
console.warn('getMorePhotos : Error', error);
console.log(error);
dispatcher.dispatch(ActionTypes.CAMERA_ROLL_GET_MORE_PHOTOS_FAILURE, {
error,
});
}
};
}
/*
* resetPhotos
* @Description: reset photos store
*/
export function resetPhotos() {
return async dispatch => {
const dispatcher = new ActionDispatcher(dispatch);
try {
dispatcher.dispatch(ActionTypes.CAMERA_ROLL_GET_PHOTOS_INIT);
} catch (error) {
console.warn('resetPhotos : Error');
console.log(error);
}
};
}
/*
* Default
*/
export default {
getPhotos,
getMorePhotos,
resetPhotos,
};