Authored by 叶弯弯

调试消息已读接口,增加读取未读消息数接口代码。reviewed by yuliang.

... ... @@ -27,6 +27,12 @@ export default keyMirror({
REQUEST_MSG_LIST: null,
REQUEST_MSG_LIST_SUCCESS: null,
REQUEST_MSG_LIST_FAILURE: null,
BATCH_SET_MSG_IS_READ: null,
BATCH_SET_MSG_IS_READ_SUCCESS: null,
BATCH_SET_MSG_IS_READ_FAILURE: null,
REQUEST_MSG_NUM: null,
REQUEST_MSG_NUM_SUCCESS: null,
REQUEST_MSG_NUM_FAILURE: null,
LOGIN_REQUEST: null,
LOGIN_SUCCESS: null,
... ...
... ... @@ -56,7 +56,7 @@ class MessageContainer extends Component {
}
pressRow(rowID){
this.props.actions.checkMessageDetail(this.props.message.messageList.toJS()[rowID]);
this.props.actions.checkMessageDetail(this.props.message.messageList.get(rowID));
}
render() {
... ...
... ... @@ -64,20 +64,26 @@ export default class MessageDetailContainer extends Component {
}
componentDidMount() {
}
componentDidMount() {
// console.log(this.props.message.messageDetail);
// if (this.props.message.messageDetail.get('isRead') === 'N') {
// this.props.actions.setMsgIsRead(this.props.message.messageDetail.get('shopsid'), this.props.message.messageDetail.get('id'));
// }
}
componentWillUnmount() {
}
render() {
if (this.props.message.messageDetail.get('isRead') === 'N') {
this.props.actions.setMsgIsRead(this.props.message.messageDetail.get('shopsid'), this.props.message.messageDetail.get('id'));
}
return (
<MessageDetail
title={this.props.message.messageDetail.title}
content={this.props.message.messageDetail.content}
time={this.props.message.messageDetail.time}
title={this.props.message.messageDetail.get('title')}
content={this.props.message.messageDetail.get('content')}
time={this.props.message.messageDetail.get('createTime')}
/>
);
... ...
... ... @@ -14,6 +14,12 @@ const {
REQUEST_MSG_LIST,
REQUEST_MSG_LIST_SUCCESS,
REQUEST_MSG_LIST_FAILURE,
BATCH_SET_MSG_IS_READ,
BATCH_SET_MSG_IS_READ_SUCCESS,
BATCH_SET_MSG_IS_READ_FAILURE,
REQUEST_MSG_NUM,
REQUEST_MSG_NUM_SUCCESS,
REQUEST_MSG_NUM_FAILURE,
} = require('../../constants/actionTypes').default;
export function checkMessageDetail(item) {
... ... @@ -57,3 +63,72 @@ export function getMsgList(shopsId) {
});
};
}
export function setMsgIsRead(shopsId, ids) {
return dispatch => {
dispatch(batchSetMsgRead());
return new MessageService().setMsgIsRead(shopsId, ids)
.then(json => {
dispatch(batchSetMsgReadSuccess(json));
})
.catch(error => {
dispatch(batchSetMsgReadFailure(error));
});
};
}
export function batchSetMsgRead() {
return {
type: BATCH_SET_MSG_IS_READ,
}
}
export function batchSetMsgReadSuccess(json) {
return {
type: BATCH_SET_MSG_IS_READ_SUCCESS,
payload: json,
}
}
export function batchSetMsgReadFailure(error) {
return {
type: BATCH_SET_MSG_IS_READ_FAILURE,
payload: error,
}
}
export function requestUnreadMsgNum(shopsId, isRead) {
return dispatch => {
dispatch(requestMsgNum());
return new MessageService().requestUnreadMsgNum(shopsId, isRead)
.then(json => {
dispatch(requestMsgNumSuccess(json));
})
.catch(error => {
dispatch(requestMsgNumFailure(error));
});
};
}
export function requestMsgNum() {
return {
type: REQUEST_MSG_NUM,
}
}
export function requestMsgNumSuccess(json) {
return {
type: REQUEST_MSG_NUM_SUCCESS,
payload: json,
}
}
export function requestMsgNumFailure(error) {
return {
type: REQUEST_MSG_NUM_FAILURE,
payload: error,
}
}
... ...
... ... @@ -7,7 +7,7 @@
/**
* ## Import immutable record
*/
import {Record, List} from 'immutable';
import {Record, List, Map} from 'immutable';
/**
* ## InitialState
... ... @@ -17,12 +17,9 @@ import {Record, List} from 'immutable';
let InitialState = Record({
isFetching: false,
error: null,
messageDetail: new (Record({
title: '',
content: '',
time: '',
})),
messageDetail: Map(),
messageList: List(),
unreadNum: 0,
});
export default InitialState;
... ...
... ... @@ -19,6 +19,12 @@ const {
REQUEST_MSG_LIST,
REQUEST_MSG_LIST_SUCCESS,
REQUEST_MSG_LIST_FAILURE,
BATCH_SET_MSG_IS_READ,
BATCH_SET_MSG_IS_READ_SUCCESS,
BATCH_SET_MSG_IS_READ_FAILURE,
REQUEST_MSG_NUM,
REQUEST_MSG_NUM_SUCCESS,
REQUEST_MSG_NUM_FAILURE,
} = require('../../constants/actionTypes').default;
/**
* ## guideReducer function
... ... @@ -30,23 +36,43 @@ export default function messageReducer(state = initialState, action) {
switch (action.type) {
case MESSAGE_DETAIL:{
let nextState = state.setIn(['messageDetail', 'title'], action.payload.title)
.setIn(['messageDetail', 'content'], action.payload.content)
.setIn(['messageDetail', 'time'], action.payload.createTime);
// let nextState = state.setIn(['messageDetail', 'title'], action.payload.title)
// .setIn(['messageDetail', 'content'], action.payload.content)
// .setIn(['messageDetail', 'time'], action.payload.createTime)
// .setIn(['messageDetail', 'id'], action.payload.id)
// .setIn(['messageDetail', 'isRead'], action.payload.isRead)
// .setIn();
let nextState = state.set('messageDetail', action.payload);
return nextState;
}
case REQUEST_MSG_LIST: {
case REQUEST_MSG_NUM:
case BATCH_SET_MSG_IS_READ:
case REQUEST_MSG_LIST:
{
let nextState = state.set('isFetching', true)
.set('error', null);
return nextState;
}
case REQUEST_MSG_NUM_SUCCESS: {
let nextState = state.set('isFetching', false)
.set('error', null)
.set('unreadNum', action.payload);
return nextState;
}
case REQUEST_MSG_LIST_SUCCESS: {
let nextState = state.set('isFetching', false)
.set('error', null)
.set('messageList', Immutable.fromJS(action.payload.list));
return nextState;
}
case REQUEST_MSG_LIST_FAILURE: {
case BATCH_SET_MSG_IS_READ_SUCCESS: {
return state.set('isFetching', false)
.set('error', null);
}
case REQUEST_MSG_NUM_FAILURE:
case BATCH_SET_MSG_IS_READ_FAILURE:
case REQUEST_MSG_LIST_FAILURE:
{
return state.set('isFetching', false)
.set('error', action.payload);
}
... ...
... ... @@ -24,4 +24,40 @@ export default class MessageService {
throw error;
});
}
async setMsgIsRead(shopsId, ids) {
return this.api.get({
url: '/gateway',
body: {
shopsId: shopsId,
ids: ids,
method: 'app.shopInbox.batchSetIsRead',
debug: 'XYZ',
}
})
.then(json => {
return json;
})
.catch(error => {
throw error;
});
}
async requestUnreadMsgNum(shopsId, isRead) {
return this.api.get({
url: '/gateway',
body: {
shopsId: shopsId,
isRead: isRead,
method: 'app.shopInbox.getShopInboxTotal',
debug: 'XYZ',
}
})
.then(json => {
return json;
})
.catch(error => {
throw error;
});
}
}
... ...