From 517c93a7d57130e9378f5eb1c260a945dbb05ba7 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sun, 26 Jul 2020 14:00:01 -0600 Subject: [PATCH] Move expand-on-filter into the sublist It's a bit more complicated this way, but helps reduce some of the latency involved in remounting the entire room list. --- src/components/views/rooms/RoomList.tsx | 1 - src/components/views/rooms/RoomSublist.tsx | 22 +++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/components/views/rooms/RoomList.tsx b/src/components/views/rooms/RoomList.tsx index 762fe0a256..f4b9de93b1 100644 --- a/src/components/views/rooms/RoomList.tsx +++ b/src/components/views/rooms/RoomList.tsx @@ -321,7 +321,6 @@ export default class RoomList extends React.PureComponent { isMinimized={this.props.isMinimized} onResize={this.props.onResize} extraBadTilesThatShouldntExist={extraTiles} - isFiltered={!!RoomListStore.instance.getFirstNameFilterCondition()} /> ); } diff --git a/src/components/views/rooms/RoomSublist.tsx b/src/components/views/rooms/RoomSublist.tsx index 63fb14de3a..5d76cf7b05 100644 --- a/src/components/views/rooms/RoomSublist.tsx +++ b/src/components/views/rooms/RoomSublist.tsx @@ -69,7 +69,6 @@ interface IProps { isMinimized: boolean; tagId: TagID; onResize: () => void; - isFiltered: boolean; // TODO: Don't use this. It's for community invites, and community invites shouldn't be here. // You should feel bad if you use this. @@ -102,17 +101,19 @@ export default class RoomSublist extends React.Component { private dispatcherRef: string; private layout: ListLayout; private heightAtStart: number; + private isBeingFiltered: boolean; constructor(props: IProps) { super(props); this.layout = RoomListLayoutStore.instance.getLayoutFor(this.props.tagId); this.heightAtStart = 0; + this.isBeingFiltered = !!RoomListStore.instance.getFirstNameFilterCondition(); this.state = { notificationState: RoomNotificationStateStore.instance.getListState(this.props.tagId), contextMenuPosition: null, isResizing: false, - isExpanded: this.props.isFiltered ? this.props.isFiltered : !this.layout.isCollapsed, + isExpanded: this.isBeingFiltered ? this.isBeingFiltered : !this.layout.isCollapsed, height: 0, // to be fixed in a moment, we need `rooms` to calculate this. rooms: RoomListStore.instance.orderedLists[this.props.tagId] || [], }; @@ -173,13 +174,6 @@ export default class RoomSublist extends React.Component { public componentDidUpdate(prevProps: Readonly, prevState: Readonly) { this.state.notificationState.setRooms(this.state.rooms); - if (prevProps.isFiltered !== this.props.isFiltered) { - if (this.props.isFiltered) { - this.setState({isExpanded: true}); - } else { - this.setState({isExpanded: !this.layout.isCollapsed}); - } - } const prevExtraTiles = prevState.filteredExtraTiles || prevProps.extraBadTilesThatShouldntExist; // as the rooms can come in one by one we need to reevaluate // the amount of available rooms to cap the amount of requested visible rooms by the layout @@ -269,6 +263,16 @@ export default class RoomSublist extends React.Component { stateUpdates.rooms = newRooms; } + const isStillBeingFiltered = !!RoomListStore.instance.getFirstNameFilterCondition(); + if (isStillBeingFiltered !== this.isBeingFiltered) { + this.isBeingFiltered = isStillBeingFiltered; + if (isStillBeingFiltered) { + stateUpdates.isExpanded = true; + } else { + stateUpdates.isExpanded = !this.layout.isCollapsed; + } + } + if (Object.keys(stateUpdates).length > 0) { this.setState(stateUpdates); }