From 9a24249fb5805bdbf9c623d2b5cbe5997ef0d85a Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 22 Nov 2018 15:13:03 +0000 Subject: [PATCH] emit focus_composer after updating the active room in GroupGridView also change the active room from there so RoomView is oblivious to grid view stuff --- src/components/structures/GroupGridView.js | 25 +++++++++++++++++++++- src/components/structures/RoomView.js | 6 +----- src/stores/OpenRoomsStore.js | 6 ++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/components/structures/GroupGridView.js b/src/components/structures/GroupGridView.js index e6c0dfd31e..0181966d49 100644 --- a/src/components/structures/GroupGridView.js +++ b/src/components/structures/GroupGridView.js @@ -28,10 +28,22 @@ export default class RoomGridView extends React.Component { super(props); this.state = { roomStores: OpenRoomsStore.getRoomStores(), + activeRoomStore: OpenRoomsStore.getActiveRoomStore(), }; this.onRoomsChanged = this.onRoomsChanged.bind(this); } + componentDidUpdate(_, prevState) { + const store = this.state.activeRoomStore; + if (store) { + store.getDispatcher().dispatch({action: 'focus_composer'}); + } + } + + componentDidMount() { + this.componentDidUpdate(); + } + componentWillMount() { this._unmounted = false; this._openRoomsStoreRegistration = OpenRoomsStore.addListener(this.onRoomsChanged); @@ -61,6 +73,16 @@ export default class RoomGridView extends React.Component { } } + _setActive(i) { + const store = OpenRoomsStore.getRoomStoreAt(i); + if (store !== this.state.activeRoomStore) { + dis.dispatch({ + action: 'group_grid_set_active', + room_id: store.getRoomId(), + }); + } + } + render() { let roomStores = this.state.roomStores.slice(0, 6); const emptyCount = 6 - roomStores.length; @@ -76,10 +98,11 @@ export default class RoomGridView extends React.Component { "mx_GroupGridView_tile": true, "mx_GroupGridView_activeTile": isActive, }); - return (
+ return (
{this._setActive(i)}} key={roomStore.getRoomId()} className={tileClasses}>
); } else { diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index c7a0677262..b1730ed96a 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -1470,10 +1470,6 @@ module.exports = React.createClass({ } }, - _onMainClicked: function() { - dis.dispatch({action: 'group_grid_set_active', room_id: this.state.room.roomId }); - }, - render: function() { const RoomHeader = sdk.getComponent('rooms.RoomHeader'); const MessageComposer = sdk.getComponent('rooms.MessageComposer'); @@ -1821,7 +1817,7 @@ module.exports = React.createClass({ const rightPanel = this.state.room ? : undefined; return ( -
+
= 0 && index < this._state.rooms.length) { + return this._state.rooms[index].store; + } + } + _getActiveOpenRoom() { const index = this._state.currentIndex; if (index !== null && index < this._state.rooms.length) {