From 03b97c25b19d64f66f4051ddbc0cacb035135da7 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sat, 12 Aug 2017 23:15:00 -0300 Subject: [PATCH] =?UTF-8?q?Fix=20room=E2=80=99s=20list=20order=20and=20loa?= =?UTF-8?q?d=20more?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/room.js | 11 +++++++---- app/views/roomsList.js | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/views/room.js b/app/views/room.js index d2c17c954..ffd2a44b7 100644 --- a/app/views/room.js +++ b/app/views/room.js @@ -98,12 +98,15 @@ export default class RoomView extends React.Component { } onEndReached = () => { - if (this.state.dataSource.length && this.state.loaded && this.state.loadingMore !== true && this.state.end !== true) { + const rowCount = this.state.dataSource.getRowCount(); + if (rowCount && this.state.loaded && this.state.loadingMore !== true && this.state.end !== true) { this.setState({ // ...this.state, loadingMore: true }); - RocketChat.loadMessagesForRoom(this.rid, this.state.dataSource[this.state.dataSource.length - 1].ts, ({ end }) => { + + const lastRowData = this.data[rowCount - 1]; + RocketChat.loadMessagesForRoom(this.rid, lastRowData.ts, ({ end }) => { this.setState({ // ...this.state, loadingMore: false, @@ -196,8 +199,8 @@ export default class RoomView extends React.Component { this.renderItem({ item })} diff --git a/app/views/roomsList.js b/app/views/roomsList.js index 04b49b673..a3d56fa50 100644 --- a/app/views/roomsList.js +++ b/app/views/roomsList.js @@ -110,9 +110,9 @@ export default class RoomsListView extends React.Component { constructor(props) { super(props); - this.data = realm.objects('subscriptions').filtered('_server.id = $0', this.props.server).sorted('_updatedAt', true); + this.data = realm.objects('subscriptions').filtered('_server.id = $0', this.props.server); this.state = { - dataSource: ds.cloneWithRows(this.data.sorted('_updatedAt', true).slice(0, 10)), + dataSource: ds.cloneWithRows([]), searching: false, searchDataSource: [], searchText: '' @@ -244,7 +244,7 @@ export default class RoomsListView extends React.Component { updateState = debounce(() => { this.setState({ - dataSource: ds.cloneWithRows(this.data.filtered('_server.id = $0', this.props.server)) + dataSource: ds.cloneWithRows(this.data.filtered('_server.id = $0', this.props.server).sorted('ls', true)) }); }, 500);