From 86817430c51cbad1234c200c61ff8de56f8ab415 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 10 Jul 2020 18:37:58 +0200 Subject: [PATCH] update initially shown amount of tiles on component update as rooms aren't all available at ctor time --- src/components/views/rooms/RoomSublist2.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/views/rooms/RoomSublist2.tsx b/src/components/views/rooms/RoomSublist2.tsx index 713b70ce94..6acb5f929c 100644 --- a/src/components/views/rooms/RoomSublist2.tsx +++ b/src/components/views/rooms/RoomSublist2.tsx @@ -142,7 +142,11 @@ export default class RoomSublist2 extends React.Component { } private get numTiles(): number { - return (this.props.rooms || []).length + (this.props.extraBadTilesThatShouldntExist || []).length; + return RoomSublist2.calcNumTiles(this.props); + } + + private static calcNumTiles(props) { + return (props.rooms || []).length + (props.extraBadTilesThatShouldntExist || []).length; } private get numVisibleTiles(): number { @@ -150,8 +154,13 @@ export default class RoomSublist2 extends React.Component { return Math.min(nVisible, this.numTiles); } - public componentDidUpdate() { + public componentDidUpdate(prevProps) { this.state.notificationState.setRooms(this.props.rooms); + // 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 + if (RoomSublist2.calcNumTiles(prevProps) !== this.numTiles) { + this.setState({height: this.calculateInitialHeight()}); + } } public componentWillUnmount() {