Authored by shangjf

站内信部分代码格式优化 review by 盖建秋

... ... @@ -11,7 +11,7 @@ import ReactNative, {
Platform,
} from 'react-native';
export default class ContentEmpty extends Component {
export default class EmptyContent extends Component {
constructor(props) {
super(props);
this.emptyText = this.emptyText.bind(this);
... ... @@ -43,15 +43,15 @@ export default class ContentEmpty extends Component {
let {listId} = this.props;
return(
<View style={styles.container}>
<Image style={styles.iconStyle}/>
<Text style={styles.textStyle}>
{this.emptyText(listId)}
</Text>
<View style={styles.aroundStyle}>
<Text style={styles.aroundTitleStyle}>
随便逛逛
<Image style={styles.iconStyle}/>
<Text style={styles.textStyle}>
{this.emptyText(listId)}
</Text>
</View>
<View style={styles.aroundStyle}>
<Text style={styles.aroundTitle}>
随便逛逛
</Text>
</View>
</View>
);
};
... ... @@ -61,35 +61,35 @@ let {width, height} = Dimensions.get('window');
let scale = (width/375.0);
let styles = StyleSheet.create({
container:{
flex:1,
flexDirection:'column',
justifyContent:'center',
alignItems:'center',
container: {
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
iconStyle:{
width:96*scale,
height:70*scale,
backgroundColor:'red',
iconStyle: {
width: Math.ceil(96*scale),
height: Math.ceil(70*scale),
backgroundColor: 'red',
},
textStyle:{
marginTop:28*scale,
color:'#444444',
backgroundColor:'transparent',
fontSize:15,
textStyle: {
marginTop: Math.ceil(28*scale),
color: '#444444',
backgroundColor: 'transparent',
fontSize: 15,
},
aroundStyle:{
marginTop:80*scale,
width:237*scale,
height:45,
backgroundColor:'#444444',
borderRadius:5,
flexDirection:'column',
justifyContent:'center',
aroundStyle: {
marginTop: Math.ceil(80*scale),
width: Math.ceil(237*scale),
height: 45,
backgroundColor: '#444444',
borderRadius: 5,
flexDirection: 'column',
justifyContent: 'center',
},
aroundTitleStyle:{
fontSize:20,
color:'white',
textAlign:'center',
aroundTitle: {
fontSize: 20,
color: 'white',
textAlign: 'center',
}
})
... ...
... ... @@ -14,7 +14,7 @@ import ReactNative, {
} from 'react-native';
import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
import ContentEmpty from './ContentEmpty';
import EmptyContent from './EmptyContent';
export default class MessageList extends Component {
... ... @@ -26,7 +26,6 @@ export default class MessageList extends Component {
});
}
componentDidMount() {
}
renderRow(rowData, sectionID, rowID) {
... ... @@ -51,11 +50,11 @@ export default class MessageList extends Component {
if (shouldShowEmpty) {
return (
<View style={styles.container}>
<ContentEmpty listId={listId}/>
<EmptyContent listId={listId}/>
</View>
);
}
return (
<View style={styles.container}>
<ListView
... ...
... ... @@ -9,7 +9,7 @@ import ReactNative, {
Platform,
} from 'react-native';
export default class MessageHeaderView extends Component {
export default class MessageListCellHeader extends Component {
constructor(props) {
super(props);
}
... ... @@ -20,7 +20,7 @@ export default class MessageHeaderView extends Component {
<Text style={styles.textStyle}>
{this.props.timestamp}
</Text>
<View style={styles.separatorStyle}/>
<View style={styles.separator}/>
</View>
)
}
... ... @@ -29,23 +29,23 @@ export default class MessageHeaderView extends Component {
let {width,height} = Dimensions.get('window');
let styles = StyleSheet.create({
container:{
flex:1,
flexDirection:'column',
container: {
flex: 1,
flexDirection: 'column',
width,
height:40,
backgroundColor:'#f2f2f2',
justifyContent:'center',
height: 40,
backgroundColor: '#f2f2f2',
justifyContent: 'center',
},
textStyle:{
fontSize:13,
backgroundColor:'transparent',
color:'#b0b0b0',
textAlign:'center',
textStyle: {
fontSize: 13,
backgroundColor: 'transparent',
color: '#b0b0b0',
textAlign: 'center',
},
separatorStyle:{
alignSelf:'flex-end',
backgroundColor:'#e0e0e0',
height:1,
separator: {
alignSelf: 'flex-end',
backgroundColor: '#e0e0e0',
height: 1,
}
})
... ...
... ... @@ -90,10 +90,10 @@ let styles = StyleSheet.create({
},
contentContainer: {
},
renderSeparatorStyle:{
left:15,
height:1,
width:width-15,
backgroundColor:'#e0e0e0',
renderSeparatorStyle: {
left: 15,
height: 1,
width: width-15,
backgroundColor: '#e0e0e0',
},
});
... ...
... ... @@ -20,12 +20,12 @@ export default class MessageCell extends Component {
renderUnreaderMsg(rowData) {
let msgNumber = rowData.get('unReadCount', 0);
if (msgNumber <= 0) {
return null;
return null;
}
return (
<View style={styles.unreadMsgContainerStyle}>
<Text style={styles.unreadMsgStyle}>
<View style={styles.unreadMsgContainer}>
<Text style={styles.unreadMsg}>
{msgNumber}
</Text>
</View>
... ... @@ -40,25 +40,25 @@ export default class MessageCell extends Component {
this.props.onPressListItem && this.props.onPressListItem(data);
}}
>
<View style={styles.rowContainer}>
<View style={styles.iconContainerStyle}>
<Image style={styles.iconStyle}/>
{this.renderUnreaderMsg(data)}
<View style={styles.rowContainer}>
<View style={styles.iconContainer}>
<Image style={styles.iconStyle}/>
{this.renderUnreaderMsg(data)}
</View>
<View style={styles.cellContent}>
<View style={styles.titleContainer}>
<Text style={styles.titleStyle}>
{data.get('inboxCatName')}
</Text>
<Text style={styles.timeStyle}>
{data.get('createTime')}
</Text>
</View>
<Text style={styles.subTitle}>
{data.get('content')}
</Text>
</View>
</View>
<View style={styles.cellContentStyle}>
<View style={styles.titleContainerStyle}>
<Text style={styles.titleStyle}>
{data.get('inboxCatName')}
</Text>
<Text style={styles.timeStyle}>
{data.get('createTime')}
</Text>
</View>
<Text style={styles.subTitleStyle}>
{data.get('content')}
</Text>
</View>
</View>
</TouchableOpacity>
);
}
... ... @@ -77,60 +77,60 @@ let styles = StyleSheet.create({
height:70,
alignItems:'center',
},
iconContainerStyle:{
iconContainer: {
flexDirection:'row',
marginLeft: 15,
marginRight:15,
backgroundColor:'transparent',
width:50,
height:50,
marginRight: 15,
backgroundColor: 'transparent',
width: 50,
height: 50,
},
iconStyle:{
backgroundColor:'yellow',
width:50,
height:50,
resizeMode:'center',
iconStyle: {
backgroundColor: 'yellow',
width: 50,
height: 50,
resizeMode: 'center',
},
unreadMsgContainerStyle:{
height:18,
marginTop:-5,
marginLeft:-12,
backgroundColor:'#d0021b',
justifyContent:'center',
borderRadius:10,
minWidth:18,
unreadMsgContainer: {
height: 18,
marginTop: -5,
marginLeft: -12,
backgroundColor: '#d0021b',
justifyContent: 'center',
borderRadius: 10,
minWidth: 18,
},
unreadMsgStyle:{
textAlign:'center',
justifyContent:'center',
fontSize:10,
color:'white',
backgroundColor:'transparent',
padding:5,
unreadMsg: {
textAlign: 'center',
justifyContent: 'center',
fontSize: 10,
color: 'white',
backgroundColor: 'transparent',
padding: 5,
},
cellContentStyle:{
flexDirection:'column',
marginRight:15,
width:width-45-50
cellContent: {
flexDirection: 'column',
marginRight: 15,
width: width-45-50
},
titleContainerStyle:{
flexDirection:'row',
alignItems:'center',
marginBottom:8,
titleContainer: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 8,
},
titleStyle:{
fontSize:15,
fontWeight:'bold',
color:'#444444',
backgroundColor:'transparent'
titleStyle: {
fontSize: 15,
fontWeight: 'bold',
color: '#444444',
backgroundColor: 'transparent'
},
timeStyle:{
fontSize:11,
color:'#b0b0b0',
timeStyle: {
fontSize: 11,
color: '#b0b0b0',
},
subTitleStyle:{
fontSize:12,
color:'#b0b0b0',
backgroundColor:'transparent'
subTitle: {
fontSize: 12,
color: '#b0b0b0',
backgroundColor: 'transparent'
}
});
... ...
... ... @@ -50,11 +50,8 @@ export function messageList() {
let page = list.currentPage + 1;
let pageSize = list.pageSize;
let uid = 0;
let sourcePage = '';
messageListParam().then((_uid,_sourcePage)=>{
uid=_uid;
sourcePage = _sourcePage;
let fetchList = (sourcePage) => {
dispatch(messageListRequest());
return new MessageListService(app.host).fetchMessageList(uid,page,pageSize,sourcePage,listId)
.then(json => {
... ... @@ -71,8 +68,15 @@ export function messageList() {
.catch(error => {
dispatch(messageListFailure(error));
});
}).catch(error=>{
});
}
ReactNative.NativeModules.YH_CommonHelper.sourcePage('YH_RNMessageViewController')
.then(result=> {
let sourcePage = result[0];
fetchList(sourcePage);
}).catch(error=> {
fetchList('');
})
};
}
... ... @@ -90,23 +94,3 @@ function parseMessageList(json) {
total,
};
}
function messageListParam(){
let uid = 0;
let sourcePage = '';
return Promise.all([
ReactNative.NativeModules.YH_CommonHelper.sourcePage('YH_RNMessageViewController'),
]).then(result => {
sourcePage = result[0];
return ReactNative.NativeModules.YH_CommonHelper.uid();
}).then(data => {
uid = data;
return {
uid,
sourcePage,
};
})
.catch(error => {
return error;
});
}
... ...
... ... @@ -43,7 +43,7 @@ export function latestMessage() {
let fetchMessage = (uid, sourcePage) => {
dispatch(latestMessageRequest());
return new MessageService(app.host).fetchInterestList(uid, sourcePage)
return new MessageService(app.host).fetchMessageCategoryList(uid, sourcePage)
.then(json => {
dispatch(latestMessageSuccess(json));
})
... ...
... ... @@ -7,26 +7,33 @@ let defaults = Immutable.fromJS([
id: '1',
inboxCatName: '会员信息',
content: '会员等级变更提醒、会员生日福利',
unReadCount:0,
createTime:''
},
{
id: '2',
inboxCatName: '我的资产',
content: '新注册用户提示新人专享优惠券信息',
unReadCount:0,
createTime:''
},
{
id: '3',
inboxCatName: '客户服务',
content: '没有收到任何关于你的消息',
unReadCount:0,
createTime:''
},
{
id: '4',
inboxCatName: '其他',
content: '没有收到任何系统给消息',
unReadCount:0,
createTime:''
},
]);
let InitialState = Record({
defaults,
latest: new (Record({
isFetching: false,
error: null,
... ...
... ... @@ -12,11 +12,10 @@ export default class MessageListService {
this.api = new Request(baseURL);
}
async fetchMessageList(uid, page, limit, fromPage, displayTab) {
async fetchMessageList(page, limit, fromPage, displayTab) {
return await this.api.get({
url: '',
body: {
uid,
page,
limit,
fromPage,
... ...
... ... @@ -12,7 +12,7 @@ export default class MessageService {
this.api = new Request(baseURL);
}
async fetchInterestList(uid, fromPage) {
async fetchMessageCategoryList(uid, fromPage) {
return await this.api.get({
url: '',
body: {
... ...