diff --git a/app/components/RoomItem.js b/app/components/RoomItem.js index cd524e459fc2fb78696a37430850b7b4aa1473a4..89ed5c1ecebb13aeb7a22ffc4ba3e75a4d298e29 100644 --- a/app/components/RoomItem.js +++ b/app/components/RoomItem.js @@ -9,10 +9,11 @@ const styles = StyleSheet.create({ alignItems: 'center' }, number: { - width: 20, - lineHeight: 20, + minWidth: 20, + fontSize: 14, + padding: 2, borderRadius: 5, - backgroundColor: 'green', + backgroundColor: '#aaa', color: '#fff', textAlign: 'center', overflow: 'hidden', @@ -47,9 +48,15 @@ export default class RoomItem extends React.PureComponent { } render() { + let name = this.props.item.name; + if (this.props.item.t === 'd') { + name = `@ ${ name }`; + } else { + name = `# ${ name }`; + } return ( <View style={styles.container}> - <Text onPress={this._onPress} style={styles.roomItem}>{ this.props.item.name }</Text> + <Text onPress={this._onPress} style={styles.roomItem}>{ name }</Text> {this.renderNumber(this.props.item)} </View> ); diff --git a/app/lib/meteor.js b/app/lib/meteor.js index f06b94f47a5b959b7f5cc24f8e70ca1ca057fca7..0ce5a5efb8fbdeddb62135baecf7b8994080b341 100644 --- a/app/lib/meteor.js +++ b/app/lib/meteor.js @@ -120,7 +120,7 @@ export function loadSubscriptions(cb) { }); } -export function loadMessagesForRoom(rid) { +export function loadMessagesForRoom(rid, cb) { Meteor.call('loadHistory', rid, null, 50, (err, data) => { if (err) { console.error(err); @@ -133,6 +133,10 @@ export function loadMessagesForRoom(rid) { realm.create('messages', message, true); }); }); + + if (cb) { + cb(); + } }); Meteor.subscribe('stream-room-messages', rid, false); diff --git a/app/lib/realm.js b/app/lib/realm.js index a6b8b286c5236f2317080d613580b6c9b9366809..af6e717d7c17089b62a84995ba3816e0b9182aa8 100644 --- a/app/lib/realm.js +++ b/app/lib/realm.js @@ -65,7 +65,7 @@ const messagesSchema = { u: 'users', // mentions: [], // channels: [], - _updatedAt: 'date', + _updatedAt: { type: 'date', optional: true }, temp: { type: 'bool', optional: true } } }; diff --git a/app/views/room.js b/app/views/room.js index 92b5993f64c3949c7d21d58b9a96a8b99df9f9f1..1548ab940916a2b62472cfd3988d0f5ad2560c8d 100644 --- a/app/views/room.js +++ b/app/views/room.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { View, FlatList, StyleSheet } from 'react-native'; +import { Text, View, FlatList, StyleSheet } from 'react-native'; // import Markdown from 'react-native-simple-markdown'; import realm from '../lib/realm'; import RocketChat, { loadMessagesForRoom, sendMessage } from '../lib/meteor'; @@ -19,9 +19,15 @@ const styles = StyleSheet.create({ }, separator: { height: 1, - // width: "86%", backgroundColor: '#CED0CE' - // marginLeft: "14%" + }, + bannerContainer: { + backgroundColor: 'orange' + }, + bannerText: { + margin: 5, + textAlign: 'center', + color: '#a00' } }); @@ -40,14 +46,20 @@ export default class RoomView extends React.Component { // this.rid = 'GENERAL'; this.state = { - dataSource: this.getMessages() + dataSource: this.getMessages(), + loaded: false }; this.url = realm.objectForPrimaryKey('settings', 'Site_Url').value; } componentWillMount() { - loadMessagesForRoom(this.rid); + loadMessagesForRoom(this.rid, () => { + this.setState({ + ...this.state, + loaded: true + }); + }); realm.addListener('change', this.updateState); } @@ -59,6 +71,7 @@ export default class RoomView extends React.Component { updateState = () => { this.setState({ + ...this.state, dataSource: this.getMessages() }); }; @@ -77,9 +90,20 @@ export default class RoomView extends React.Component { /> ); + renderBanner = () => { + if (this.state.loaded === false) { + return ( + <View style={styles.bannerContainer}> + <Text style={styles.bannerText}>Loading new messages...</Text> + </View> + ); + } + } + render() { return ( <KeyboardView style={styles.container} keyboardVerticalOffset={64}> + {this.renderBanner()} <FlatList ref={ref => this.listView = ref} style={styles.list} diff --git a/app/views/roomsList.js b/app/views/roomsList.js index adb8deda29992d2e4ed72659b4cd40e5bc461aa2..f76bddcf3bb53ac1c35a6ed42e4e96f39dc40fd5 100644 --- a/app/views/roomsList.js +++ b/app/views/roomsList.js @@ -20,6 +20,11 @@ const styles = StyleSheet.create({ list: { width: '100%' }, + emptyView: { + flexGrow: 1, + alignItems: 'stretch', + justifyContent: 'center' + }, emptyText: { textAlign: 'center', fontSize: 18, @@ -29,8 +34,8 @@ const styles = StyleSheet.create({ backgroundColor: '#ddd' }, bannerText: { - lineHeight: 28, - textAlign: 'center' + textAlign: 'center', + margin: 5 } }); @@ -107,18 +112,20 @@ export default class RoomsListView extends React.Component { } renderBanner = () => { - if (Meteor.getData().ddp.status !== 'connected') { + const status = Meteor.getData() && Meteor.getData().ddp && Meteor.getData().ddp.status; + + if (status === 'disconnected') { return ( - <View style={styles.bannerContainer}> - <Text style={styles.bannerText}>Connecting...</Text> + <View style={[styles.bannerContainer, { backgroundColor: '#0d0' }]}> + <Text style={[styles.bannerText, { color: '#fff' }]}>Connecting...</Text> </View> ); } - if (Meteor._isLoggingIn) { + if (status === 'connected' && Meteor._isLoggingIn) { return ( - <View style={styles.bannerContainer}> - <Text style={styles.bannerText}>Loggining...</Text> + <View style={[styles.bannerContainer, { backgroundColor: 'orange' }]}> + <Text style={[styles.bannerText, { color: '#a00' }]}>Authenticating...</Text> </View> ) } @@ -150,7 +157,9 @@ export default class RoomsListView extends React.Component { } return ( - <Text style={styles.emptyText}>No rooms</Text> + <View style={styles.emptyView}> + <Text style={styles.emptyText}>No rooms</Text> + </View> ); }