From f5d490ee78559b7b0889f3d36424bb311293131f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 19 Mar 2020 23:11:28 +0000 Subject: [PATCH] Tidy up code Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/RoomSubList.js | 5 ----- src/components/views/rooms/RoomTile.js | 23 ++++++++++++++++------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/structures/RoomSubList.js b/src/components/structures/RoomSubList.js index 5ab8ab60ee..5ae240013c 100644 --- a/src/components/structures/RoomSubList.js +++ b/src/components/structures/RoomSubList.js @@ -130,11 +130,6 @@ export default class RoomSubList extends React.PureComponent { this.props.list.some((r) => r.roomId === payload.room_id) ) { this.onClick(); - // re-fire to scroll the room tile, normally it catches `view_room` but here it wasn't rendered yet. - dis.dispatch({ - action: 'scroll_room_tile', - room_id: payload.room_id, - }); } } }; diff --git a/src/components/views/rooms/RoomTile.js b/src/components/views/rooms/RoomTile.js index 9a04887483..0f44f5077a 100644 --- a/src/components/views/rooms/RoomTile.js +++ b/src/components/views/rooms/RoomTile.js @@ -226,19 +226,23 @@ export default createReactClass({ this.forceUpdate(); break; - case 'scroll_room_tile': case 'view_room': - // when the room is selected make sure its tile is visible, for breadcrumbs/keyboard shortcuts - if (payload.room_id === this.props.room.roomId && this._roomTile.current) { - this._roomTile.current.scrollIntoView({ - block: "nearest", - behavior: "auto", - }); + // when the room is selected make sure its tile is visible, for breadcrumbs/keyboard shortcut access + if (payload.room_id === this.props.room.roomId) { + this._scrollIntoView(); } break; } }, + _scrollIntoView: function() { + if (!this._roomTile.current) return; + this._roomTile.current.scrollIntoView({ + block: "nearest", + behavior: "auto", + }); + }, + _onActiveRoomChange: function() { this.setState({ selected: this.props.room.roomId === RoomViewStore.getRoomId(), @@ -272,6 +276,11 @@ export default createReactClass({ statusUser.on("User._unstable_statusMessage", this._onStatusMessageCommitted); } } + + // when we're first rendered (or our sublist is expanded) make sure we are visible if we're active + if (this.state.selected) { + this._scrollIntoView(); + } }, componentWillUnmount: function() {