subjectPostActions.js
2.35 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
/**
* # guideActions.js
*
* App user guide
*
*/
'use strict';
import {Actions} from 'react-native-router-flux';
import PostingService from '../../services/PostingService';
import Immutable, {List, Record} from 'immutable';
import {
NativeModules,
} from 'react-native';
const {
SUBJECT_CONTENT_REQUEST,
SUBJECT_CONTENT_SUCCESS,
SUBJECT_CONTENT_FAILURE,
SUBJECT_COMMENTS_REQUEST,
SUBJECT_COMMENTS_SUCCESS,
SUBJECT_COMMENTS_FAILURE,
} = require('../../constants/actionTypes').default;
export function requestPostContent(postsId) {
return dispatch => {
dispatch(doRequestContent());
let params = {postsId};
new PostingService().getPostContent(params)
.then(json => {
NativeModules.YH_CommunityHelper.uid()
.then(uid => {
json.LZ = (uid == json.authorInfo.uid);
dispatch(contentRequestSuccess(json));
})
.catch(error => {
json.LZ = false;
dispatch(contentRequestSuccess(json));
});
})
.catch(error => {
dispatch(contentRequestFailure(error));
});
}
}
export function doRequestContent() {
return {
type: SUBJECT_CONTENT_REQUEST,
}
}
export function contentRequestSuccess(json) {
return {
type: SUBJECT_CONTENT_SUCCESS,
payload: json,
}
}
export function contentRequestFailure(error) {
return {
type: SUBJECT_CONTENT_FAILURE,
payload: error,
}
}
export function requestPostComments(postsId, lastedTime) {
return dispatch => {
dispatch(doRequestComments());
let params = {
postsId,
lastedTime,
limit: 10,
};
new PostingService().getPostComments(params)
.then(json => {
dispatch(commentsRequestSuccess(json));
})
.catch(error => {
dispatch(commentsRequestFailure(error));
});
}
}
export function doRequestComments() {
return {
type: SUBJECT_COMMENTS_REQUEST,
}
}
export function commentsRequestSuccess(json) {
return {
type: SUBJECT_COMMENTS_SUCCESS,
payload: json,
}
}
export function commentsRequestFailure(error) {
return {
type: SUBJECT_COMMENTS_FAILURE,
payload: error,
}
}