Authored by 张文文

添加回复评论和关注用户接口联调

... ... @@ -16,15 +16,12 @@ export default class ContentFansListCell extends Component {
render() {
let {data} = this.props;
let resource = data.isMutualAttention ? require('../../images/content_attentioned.png') : require('../../images/content_fan.png');
let status = data.isMutualAttention ? 1 : 0;
function onHeadIconPress() {
}
function onFanButtonPress() {
}
return (
<View>
<View style={styles.headerBackground}>
... ... @@ -39,7 +36,7 @@ export default class ContentFansListCell extends Component {
</Text>
<Text style={styles.startTimeText}>{data.createTime}</Text>
</View>
<TouchableOpacity activeOpacity={1} style={styles.fanContainer} onPress={()=> {onFanButtonPress()}}>
<TouchableOpacity activeOpacity={1} style={styles.fanContainer} onPress={()=> {this.props.updateAttentionAction && this.props.updateAttentionAction(status)}}>
<Image style={styles.fanImage} source={resource}/>
</TouchableOpacity>
</View>
... ...
... ... @@ -39,6 +39,7 @@ export default class ContentListView extends Component {
<ContentFansListCell
key={'row'+ rowID}
data={rowData}
updateAttentionAction={this.props.updateAttentionAction}
/>
}
... ...
... ... @@ -40,9 +40,15 @@ export default keyMirror({
FETCH_CONTENT_LIST_SUCCESS: null,
FETCH_CONTENT_LIST_FAILURE: null,
ADD_CONTENT_INBOX_REQUEST: null,
ADD_CONTENT_INBOX_SUCCESS: null,
ADD_CONTENT_INBOX_FAILURE: null,
//回复评论
ADD_ARTICLE_COMMENT_REQUEST: null,
ADD_ARTICLE_COMMENT_SUCCESS: null,
ADD_ARTICLE_COMMENT_FAILURE: null,
//关注用户
UPDATE_ATTENTION_REQUEST: null,
UPDATE_ATTENTION_SUCCESS: null,
UPDATE_ATTENTION_FAILURE: null,
MESSAGE_CLEAR_OTHER_LIST: null,
MESSAGE_CLEAR_COMMENT_LIST: null,
... ...
... ... @@ -44,12 +44,16 @@ class ContentListContainer extends Component {
constructor(props) {
super(props);
this.updateAttentionAction = this.updateAttentionAction.bind(this);
}
componentDidMount() {
updateAttentionAction(status) {
this.props.actions.updateAttentionAction(status);
}
componentDidMount() {
this.props.actions.getContentList(true, this.props.contentListId)
}
componentWillUnmount() {
... ... @@ -68,6 +72,7 @@ class ContentListContainer extends Component {
contentListId={this.props.contentListId}
onRefresh={this._onRefresh}
onEndReached={this._onEndReached}
updateAttentionAction={this.updateAttentionAction}
/>
</View>
... ...
... ... @@ -46,10 +46,10 @@ class ContentMessageContainer extends Component {
super(props);
this.state = {
businessType: 0,
commentId: 0,
dataSource : {},
};
this._onRefresh = this._onRefresh.bind(this)
this._onRefresh = this._onRefresh.bind(this);
this._onEndReached = this._onEndReached.bind(this);
this._storeReplySource = this._storeReplySource.bind(this);
}
... ... @@ -79,16 +79,19 @@ class ContentMessageContainer extends Component {
}
_addInBoxAction(addValue) {
// this.props.actions.addContentInBox(this.state.businessType, this.state.commentId, addValue)
let addType = this.state.dataSource.businessType === 1003 ? 1 : 0;
let destId = addType === 0 ? this.state.dataSource.articleId : 0;
let commentId = this.state.dataSource.commentId;
let columnType = addType === 0? 1001 : 0;
this.props.actions.addArticleCommentAction(addValue, destId, commentId, addType, columnType);
}
_storeReplySource(dataSource) {
console.log(dataSource.businessType);
this.setState = ({
businessType: dataSource.businessType,
commentId: dataSource.commentId,
this.setState({
dataSource: dataSource,
});
console.log(this.state.businessType);
}
render() {
... ...
... ... @@ -19,10 +19,15 @@ const {
FETCH_CONTENT_LIST_SUCCESS,
FETCH_CONTENT_LIST_FAILURE,
//新增回复或关注
ADD_CONTENT_INBOX_REQUEST,
ADD_CONTENT_INBOX_SUCCESS,
ADD_CONTENT_INBOX_FAILURE,
//回复评论
ADD_ARTICLE_COMMENT_REQUEST,
ADD_ARTICLE_COMMENT_SUCCESS,
ADD_ARTICLE_COMMENT_FAILURE,
//关注用户
UPDATE_ATTENTION_REQUEST,
UPDATE_ATTENTION_SUCCESS,
UPDATE_ATTENTION_FAILURE,
//清除消息内容
MESSAGE_CLEAR_OTHER_LIST,
... ... @@ -95,22 +100,42 @@ export function getContentListFailure(error, isLatest) {
}
}
export function addContentInBoxRequest() {
export function addArticleCommentRequest() {
return {
type: ADD_ARTICLE_COMMENT_REQUEST,
}
}
export function addArticleCommentSuccess(json) {
return {
type: ADD_ARTICLE_COMMENT_SUCCESS,
payload: json,
}
}
export function addArticleCommentFailure(error) {
return {
type: ADD_CONTENT_INBOX_REQUEST,
type: ADD_ARTICLE_COMMENT_FAILURE,
payload: error,
}
}
export function updateAttentionRequest() {
return {
type: UPDATE_ATTENTION_REQUEST,
}
}
export function addContentInBoxSuccess(json) {
export function updateAttentionSuccess(json) {
return {
type: ADD_CONTENT_INBOX_SUCCESS,
type: UPDATE_ATTENTION_SUCCESS,
payload: json,
}
}
export function addContentInBoxFailure(error) {
export function updateAttentionFailure(error) {
return {
type: ADD_CONTENT_INBOX_FAILURE,
type: UPDATE_ATTENTION_FAILURE,
payload: error,
}
}
... ... @@ -252,18 +277,18 @@ function parseContentList(json) {
}
}
//新增消息
export function addContentInBox(businessType, attachId, addValue) {
//回复评论
export function addArticleCommentAction(content, destId, commentId, addType, columnType) {
return (dispatch, getState) => {
let {app} = getState();
let processor = (uid)=> {
dispatch(addContentInBoxRequest());
return new ContentService().addMessageInBox(businessType, attachId, addValue, uid)
dispatch(addArticleCommentRequest());
return new ContentService().addArticleComment(content, destId, uid, commentId, addType, columnType)
.then(json => {
dispatch(addContentInBoxSuccess(json));
dispatch(addArticleCommentSuccess(json));
})
.catch(error => {
dispatch(addContentInBoxFailure(error));
dispatch(addArticleCommentFailure(error));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
... ... @@ -282,6 +307,37 @@ export function addContentInBox(businessType, attachId, addValue) {
};
}
//关注用户
export function updateAttentionAction(attentionStatus) {
return (dispatch, getState) => {
let {app} = getState();
let processor = (uid)=> {
dispatch(updateAttentionRequest());
return new ContentService().updateAttention(uid, attentionStatus)
.then(json => {
dispatch(updateAttentionSuccess(json));
})
.catch(error => {
dispatch(updateAttentionFailure(error));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
processor(uid)
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
processor(uid)
})
.catch(error => {
});
});
};
}
export function clearCommentMessageList() {
return (dispatch) => {
dispatch(clearCommentMessageListAction());
... ...
... ... @@ -16,7 +16,7 @@ let InitialState = Record({
error:null,
})),
//查询消息
//main页面消息
commentList: new (Record({
isFetching: false,
list: List(),
... ... @@ -27,6 +27,7 @@ let InitialState = Record({
shouldShowEmpty: false,
pageCount: 0,
})),
//列表页面
contentList: new (Record({
isFetching: false,
list: List(),
... ... @@ -38,7 +39,11 @@ let InitialState = Record({
pageCount: 0,
})),
addContent: new (Record({
addCommentContent: new (Record({
isFetching: false,
error: null,
})),
updateAttentionContent: new (Record({
isFetching: false,
error: null,
})),
... ...
... ... @@ -16,9 +16,15 @@ const {
FETCH_CONTENT_LIST_SUCCESS,
FETCH_CONTENT_LIST_FAILURE,
ADD_CONTENT_INBOX_REQUEST,
ADD_CONTENT_INBOX_SUCCESS,
ADD_CONTENT_INBOX_FAILURE,
//回复评论
ADD_ARTICLE_COMMENT_REQUEST,
ADD_ARTICLE_COMMENT_SUCCESS,
ADD_ARTICLE_COMMENT_FAILURE,
//关注用户
UPDATE_ATTENTION_REQUEST,
UPDATE_ATTENTION_SUCCESS,
UPDATE_ATTENTION_FAILURE,
//清除消息内容
MESSAGE_CLEAR_OTHER_LIST,
... ... @@ -97,17 +103,30 @@ export default function grassReducer(state=initialState, action) {
.setIn([getContentListObject(action.isLatest), 'shouldShowEmpty'], true);
}
case ADD_CONTENT_INBOX_REQUEST: {
return state.setIn(['addContent', 'isFetching'], true);
case ADD_ARTICLE_COMMENT_REQUEST: {
return state.setIn(['addCommentContent', 'isFetching'], true);
}
case ADD_ARTICLE_COMMENT_SUCCESS: {
return state.setIn(['addCommentContent', 'isFetching'], false);
}
case ADD_ARTICLE_COMMENT_FAILURE: {
return state.setIn(['addCommentContent', 'isFetching'], false)
.setIn(['addCommentContent', 'error'], action.payload);
}
case UPDATE_ATTENTION_REQUEST: {
return state.setIn(['updateAttentionContent', 'isFetching'], true);
}
case ADD_CONTENT_INBOX_SUCCESS: {
return state.setIn(['addContent', 'isFetching'], false);
case UPDATE_ATTENTION_SUCCESS: {
return state.setIn(['updateAttentionContent', 'isFetching'], false);
}
case ADD_CONTENT_INBOX_FAILURE: {
return state.setIn(['addContent', 'isFetching'], false)
.setIn(['addContent', 'error'], action.payload);
case UPDATE_ATTENTION_FAILURE: {
return state.setIn(['updateAttentionContent', 'isFetching'], false)
.setIn(['updateAttentionContent', 'error'], action.payload);
}
case MESSAGE_CLEAR_OTHER_LIST: {
... ...
... ... @@ -48,16 +48,40 @@ export default class ContentService {
})
}
//新增消息,关注,回复等
async addMessageInBox(businessType, attachId, addValue, uid) {
//评论(回复)接口
async addArticleComment(content, destId, uid, commentId, addType, columnType) {
return await this.api.get({
url: '',
body: {
businessType,
attachValue: attachId,
params: addValue,
optUid: uid,
method: 'app.grass.addInBox',
content,
destId,
commentId,
addType,
columnType,
uid,
method: 'app.grass.addArticleComment',
}
})
.then(json => {
return json
})
.catch(error => {
throw(error)
})
}
//关注用户接口
async updateAttention(uid, attentionStatus) {
return await this.api.get({
url: '',
body: {
uid: uid,
topicId: 1,
followUid: '1',
status: attentionStatus, //状态(0:关注,1:取消)
attentionType: 1, //类型(0:话题,1:用户)
authorType: 1,
method: 'app.grass.updateAttention',
}
})
.then(json => {
... ...