diff --git a/src/components/structures/FilePanel.js b/src/components/structures/FilePanel.js index 58888d39b3..b8752da619 100644 --- a/src/components/structures/FilePanel.js +++ b/src/components/structures/FilePanel.js @@ -34,14 +34,27 @@ var FilePanel = React.createClass({ getInitialState: function() { return { - room: MatrixClientPeg.get().getRoom(this.props.roomId), timelineSet: null, } }, componentWillMount: function() { - if (this.state.room) { - var client = MatrixClientPeg.get(); + this.updateTimelineSet(this.props.roomId); + }, + + componentWillReceiveProps: function(nextProps) { + if (nextProps.roomId !== this.props.roomId) { + // otherwise we race between updating the TimelinePanel and determining the new timelineSet + this.setState({ timelineSet: null }); + this.updateTimelineSet(nextProps.roomId); + } + }, + + updateTimelineSet: function(roomId) { + var client = MatrixClientPeg.get(); + var room = client.getRoom(roomId); + + if (room) { var filter = new Matrix.Filter(client.credentials.userId); filter.setDefinition( { @@ -56,7 +69,7 @@ var FilePanel = React.createClass({ client.getOrCreateFilter("FILTER_FILES_" + client.credentials.userId, filter).then( (filterId)=>{ filter.filterId = filterId; - var timelineSet = this.state.room.getOrCreateFilteredTimelineSet(filter); + var timelineSet = room.getOrCreateFilteredTimelineSet(filter); this.setState({ timelineSet: timelineSet }); }, (error)=>{ @@ -80,20 +93,11 @@ var FilePanel = React.createClass({ var TimelinePanel = sdk.getComponent("structures.TimelinePanel"); var Loader = sdk.getComponent("elements.Spinner"); - //