Sort room's list

This commit is contained in:
Rodrigo Nascimento 2017-08-09 15:01:54 -03:00
parent b38c072f51
commit 1c41214b52
4 changed files with 49 additions and 10 deletions

View File

@ -111,7 +111,8 @@
"quotes": [2, "single"],
"semi": [2, "always"],
"prefer-const": 2,
"object-shorthand": 2
"object-shorthand": 2,
"consistent-return": 0
},
"globals": {}
}

View File

@ -50,7 +50,6 @@ export default class MessageBox extends React.PureComponent {
returnKeyType='send'
onSubmitEditing={this.submit}
blurOnSubmit={false}
autoFocus
placeholder='New message'
/>
</View>

View File

@ -1,20 +1,36 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Text, StyleSheet } from 'react-native';
import { View, Text, StyleSheet } from 'react-native';
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
alignItems: 'center'
},
number: {
width: 20,
lineHeight: 20,
borderRadius: 5,
backgroundColor: 'green',
color: '#fff',
textAlign: 'center',
overflow: 'hidden',
marginRight: 15
},
roomItem: {
lineHeight: 18,
borderTopWidth: 2,
borderColor: '#aaa',
padding: 14
padding: 14,
flexGrow: 1
}
});
export default class RoomItem extends React.PureComponent {
static propTypes = {
onPressItem: PropTypes.func.isRequired,
title: PropTypes.string.isRequired,
item: PropTypes.object.isRequired,
id: PropTypes.string.isRequired
}
@ -22,9 +38,22 @@ export default class RoomItem extends React.PureComponent {
this.props.onPressItem(this.props.id);
};
render() {
renderNumber = (item) => {
if (item.unread) {
return (
<Text onPress={this._onPress} style={styles.roomItem}>{ this.props.title }</Text>
<Text style={styles.number}>
{ item.unread }
</Text>
);
}
}
render() {
return (
<View style={styles.container}>
<Text onPress={this._onPress} style={styles.roomItem}>{ this.props.item.name }</Text>
{this.renderNumber(this.props.item)}
</View>
);
}
}

View File

@ -62,8 +62,7 @@ export default class RoomsListView extends React.Component {
navigation = this.props.navigation;
const currentServer = realm.objects('servers').filtered('current = true')[0];
if (currentServer) {
if (RocketChat.currentServer) {
connect(() => {
// navigation.navigate('Login');
});
@ -77,7 +76,18 @@ export default class RoomsListView extends React.Component {
}
getState = () => ({
dataSource: realm.objects('subscriptions').filtered('_server.id = $0', RocketChat.currentServer).sorted('name')
dataSource: realm.objects('subscriptions').filtered('_server.id = $0', RocketChat.currentServer).sorted('name').slice()
.sort((a, b) => {
if (a.unread < b.unread) {
return 1;
}
if (a.unread > b.unread) {
return -1;
}
return 0;
})
})
updateState = () => {
@ -93,7 +103,7 @@ export default class RoomsListView extends React.Component {
<RoomItem
id={item._id}
onPressItem={this._onPressItem}
title={item.name}
item={item}
/>
);