subjectPostActions.js
3.39 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
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
/**
* # 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';
import timeago from 'timeago.js';
const {
SUBJECT_CONTENT_REQUEST,
SUBJECT_CONTENT_SUCCESS,
SUBJECT_CONTENT_FAILURE,
SUBJECT_COMMENTS_REQUEST,
SUBJECT_COMMENTS_SUCCESS,
SUBJECT_COMMENTS_FAILURE,
SUBJECT_ASSETS_SELECTED,
} = 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 => {
console.log(json);
dispatch(commentsRequestSuccess(json));
})
.catch(error => {
console.log(error);
dispatch(commentsRequestFailure(error));
});
}
}
export function doRequestComments() {
return {
type: SUBJECT_COMMENTS_REQUEST,
}
}
export function commentsRequestSuccess(json) {
let {list} = json;
let newList = [];
list && list.map((obj,i)=> {
let {createTime, reply, replyTo, blocks} = obj;
let timeagoStr = timeago().format(createTime, 'zh_CN');
let newBlocks = [];
blocks && blocks.map((blockItem, i) => {
let {commentId,content,templateKey,orderBy} = blockItem;
let newItem = {
"contentData": content,
"order": orderBy,
"templateKey": templateKey,
};
newBlocks.push(newItem);
})
let newObj={
timeago: timeagoStr,
headIcon: reply.headIcon,
nickName: reply.nickName,
LZ:false,
blocks: newBlocks,
}
newList.push(newObj);
})
json.list = newList;
return {
type: SUBJECT_COMMENTS_SUCCESS,
payload: json,
}
}
export function commentsRequestFailure(error) {
return {
type: SUBJECT_COMMENTS_FAILURE,
payload: error,
}
}
export function assetsSelected(assets) {
return {
type: SUBJECT_ASSETS_SELECTED,
payload: assets,
}
}