Sort room's list
This commit is contained in:
parent
b38c072f51
commit
1c41214b52
|
@ -111,7 +111,8 @@
|
||||||
"quotes": [2, "single"],
|
"quotes": [2, "single"],
|
||||||
"semi": [2, "always"],
|
"semi": [2, "always"],
|
||||||
"prefer-const": 2,
|
"prefer-const": 2,
|
||||||
"object-shorthand": 2
|
"object-shorthand": 2,
|
||||||
|
"consistent-return": 0
|
||||||
},
|
},
|
||||||
"globals": {}
|
"globals": {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@ export default class MessageBox extends React.PureComponent {
|
||||||
returnKeyType='send'
|
returnKeyType='send'
|
||||||
onSubmitEditing={this.submit}
|
onSubmitEditing={this.submit}
|
||||||
blurOnSubmit={false}
|
blurOnSubmit={false}
|
||||||
autoFocus
|
|
||||||
placeholder='New message'
|
placeholder='New message'
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
|
@ -1,20 +1,36 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Text, StyleSheet } from 'react-native';
|
import { View, Text, StyleSheet } from 'react-native';
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
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: {
|
roomItem: {
|
||||||
lineHeight: 18,
|
lineHeight: 18,
|
||||||
borderTopWidth: 2,
|
borderTopWidth: 2,
|
||||||
borderColor: '#aaa',
|
borderColor: '#aaa',
|
||||||
padding: 14
|
padding: 14,
|
||||||
|
flexGrow: 1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default class RoomItem extends React.PureComponent {
|
export default class RoomItem extends React.PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
onPressItem: PropTypes.func.isRequired,
|
onPressItem: PropTypes.func.isRequired,
|
||||||
title: PropTypes.string.isRequired,
|
item: PropTypes.object.isRequired,
|
||||||
id: PropTypes.string.isRequired
|
id: PropTypes.string.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +38,22 @@ export default class RoomItem extends React.PureComponent {
|
||||||
this.props.onPressItem(this.props.id);
|
this.props.onPressItem(this.props.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
renderNumber = (item) => {
|
||||||
|
if (item.unread) {
|
||||||
|
return (
|
||||||
|
<Text style={styles.number}>
|
||||||
|
{ item.unread }
|
||||||
|
</Text>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Text onPress={this._onPress} style={styles.roomItem}>{ this.props.title }</Text>
|
<View style={styles.container}>
|
||||||
|
<Text onPress={this._onPress} style={styles.roomItem}>{ this.props.item.name }</Text>
|
||||||
|
{this.renderNumber(this.props.item)}
|
||||||
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,8 +62,7 @@ export default class RoomsListView extends React.Component {
|
||||||
|
|
||||||
navigation = this.props.navigation;
|
navigation = this.props.navigation;
|
||||||
|
|
||||||
const currentServer = realm.objects('servers').filtered('current = true')[0];
|
if (RocketChat.currentServer) {
|
||||||
if (currentServer) {
|
|
||||||
connect(() => {
|
connect(() => {
|
||||||
// navigation.navigate('Login');
|
// navigation.navigate('Login');
|
||||||
});
|
});
|
||||||
|
@ -77,7 +76,18 @@ export default class RoomsListView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
getState = () => ({
|
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 = () => {
|
updateState = () => {
|
||||||
|
@ -93,7 +103,7 @@ export default class RoomsListView extends React.Component {
|
||||||
<RoomItem
|
<RoomItem
|
||||||
id={item._id}
|
id={item._id}
|
||||||
onPressItem={this._onPressItem}
|
onPressItem={this._onPressItem}
|
||||||
title={item.name}
|
item={item}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue