SubjectPostContainer.js
6.6 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
'use strict';
import React, {Component} from 'react';
import {
View,
StyleSheet,
Dimensions,
Platform,
InteractionManager,
NativeModules,
} from 'react-native';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import timeago from 'timeago.js';
import Immutable, {List, Record} from 'immutable';
import {Actions} from 'react-native-router-flux';
import SubjectPost from '../components/subjectPost/SubjectPost';
import * as subjectPostActions from '../reducers/subject/subjectPostActions';
import * as homeActions from '../reducers/home/homeActions';
const actions = [
subjectPostActions,
homeActions,
];
/**
* Save that state
*/
function mapStateToProps(state) {
return {
...state
};
}
/**
* Bind all the functions from the ```actions``` and bind them with
* ```dispatch```
*/
function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();
return {
actions: bindActionCreators(creators, dispatch),
dispatch
};
}
class SubjectPostContainer extends Component {
constructor(props) {
super(props);
this.onEndReached = this.onEndReached.bind(this);
this.assetsSelected = this.assetsSelected.bind(this);
this.commentWithParams = this.commentWithParams.bind(this);
this.onPressAvatar = this.onPressAvatar.bind(this);
this.onPressSection = this.onPressSection.bind(this);
this.onPressReportOrDelete = this.onPressReportOrDelete.bind(this);
this.onPressLikeCell = this.onPressLikeCell.bind(this);
this.onPressLikeOrDislike = this.onPressLikeOrDislike.bind(this);
this.onPressShareGoods = this.onPressShareGoods.bind(this);
this.onPressLargeImage = this.onPressLargeImage.bind(this);
this.sid = this.props.subject.sid;
}
componentDidMount() {
let item = this.props.subject.items.get(this.sid);
InteractionManager.runAfterInteractions(() => {
this.props.actions.requestPostContent(this.sid,item.id);
this.props.actions.requestPostComments(this.sid,item.id);
});
}
componentWillUnmount() {
}
onEndReached() {
let item = this.props.subject.items.get(this.sid);
if (item.currentPage>=item.totalPages) {
return;
}
this.props.actions.requestPostComments(this.sid, item.id, item.lastedTime);
}
onPressLargeImage(index) {
NativeModules.YH_CommunityHelper.showLargeImages(this.props.subject.largeImages,index);
}
assetsSelected(assets) {
this.props.actions.assetsSelected(this.sid,assets);
}
commentWithParams(params) {
this.props.actions.commentWithParams(this.sid,params);
}
onPressShareGoods() {
let item = this.props.subject.items.get(this.sid);
let params = {
productSkn: item.shareProductSkn,
};
NativeModules.YH_CommunityHelper.displayProductDetail(params);
}
onPressAvatar(uid) {
this.props.actions.goToUserOrMe(uid);
}
onPressSection(section) {
this.props.actions.goToSection(section);
}
onPressReportOrDelete() {
let item = this.props.subject.items.get(this.sid);
if (item.LZ) {
this.props.actions.doDelete(this.sid,item.id);
} else {
let params = {
postsId: item.id,
loginUid: this.props.user.profile.uid,
contentData: '涉黄',
}
this.props.actions.doReport(this.sid,params);
}
}
onPressLikeOrDislike() {
let item = this.props.subject.items.get(this.sid);
if (item.inLikeAction) {
return;
}
if (item.hasPraise == 'Y') {
this.props.actions.subjectUnlike(this.sid,item.id);
}else if(this.props.subject.hasPraise == 'N'){
this.props.actions.subjectLike(this.sid,item.id);
}
}
onPressLikeCell(postId, likeCount) {
this.props.actions.goToLikeList(postId, likeCount);
}
render() {
let item = this.props.subject.items.get(this.sid);
let {headIcon,nickName,uid} = item.authorInfo;
let timeagoStr = timeago().format(item.createTime, 'zh_CN');
let header = {
uid,
headIcon,
nickName,
forumCode: item.forumCode,
forumName: item.forumName,
timeago: timeagoStr,
LZ: item.LZ,
}
let likeData = {
praiseUsers: item.praiseUsers.toJS(),
praise: item.praise,
browse: item.browse,
postId: item.id,
}
let shareGoods = [];
if (item.shareGoods.productName.length) {
shareGoods.push(item.shareGoods);
}
let dataBlob = {
header : [header],
title: [item.postsTitle],
content: [item.blocks.toJS()],
shareGoods,
like: [likeData],
comments: item.commentList.toJS(),
};
return (
<View style={styles.container}>
<SubjectPost
dataBlob={dataBlob}
onEndReached={this.onEndReached}
endReached={item.currentPage>=item.totalPages}
isFetching={item.isCommentsFetching}
assetsSelected={this.assetsSelected}
assets={item.assets.toJS()}
commentCount={item.commentCount}
commentWithParams={this.commentWithParams}
postId={item.id}
cidFrom={this.props.user.profile.uid}
authorUid={item.authorInfo.uid}
onPressAvatar={this.onPressAvatar}
onPressSection={this.onPressSection}
onPressReportOrDelete={this.onPressReportOrDelete}
onPressLikeCell={this.onPressLikeCell}
onPressLikeOrDislike={this.onPressLikeOrDislike}
likeState={item.hasPraise}
onPressShareGoods={this.onPressShareGoods}
onPressLargeImage={this.onPressLargeImage}
/>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let navbarHeight = (Platform.OS === 'android') ? 50 : 64;
let styles = StyleSheet.create({
container: {
top: navbarHeight,
height: height - navbarHeight - 49,
},
});
export default connect(mapStateToProps, mapDispatchToProps)(SubjectPostContainer);