From 8d522099350b74df337d71c53952865a852e8010 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 9 Aug 2017 17:08:50 -0300 Subject: [PATCH] Add loading banners --- app/components/RoomItem.js | 15 +++++++++++---- app/lib/meteor.js | 6 +++++- app/lib/realm.js | 2 +- app/views/room.js | 34 +++++++++++++++++++++++++++++----- app/views/roomsList.js | 27 ++++++++++++++++++--------- 5 files changed, 64 insertions(+), 20 deletions(-) diff --git a/app/components/RoomItem.js b/app/components/RoomItem.js index cd524e459..89ed5c1ec 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 ( - { this.props.item.name } + { name } {this.renderNumber(this.props.item)} ); diff --git a/app/lib/meteor.js b/app/lib/meteor.js index f06b94f47..0ce5a5efb 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 a6b8b286c..af6e717d7 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 92b5993f6..1548ab940 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 ( + + Loading new messages... + + ); + } + } + render() { return ( + {this.renderBanner()} this.listView = ref} style={styles.list} diff --git a/app/views/roomsList.js b/app/views/roomsList.js index adb8deda2..f76bddcf3 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 ( - - Connecting... + + Connecting... ); } - if (Meteor._isLoggingIn) { + if (status === 'connected' && Meteor._isLoggingIn) { return ( - - Loggining... + + Authenticating... ) } @@ -150,7 +157,9 @@ export default class RoomsListView extends React.Component { } return ( - No rooms + + No rooms + ); }