From 990d84df776ed6e57cc8f700e64e1eb03c55d2e4 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 7 Sep 2016 15:43:14 +0100 Subject: [PATCH] make FilePanel refresh when we switch rooms --- src/components/structures/FilePanel.js | 42 +++++++++++++++----------- 1 file changed, 25 insertions(+), 17 deletions(-) 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"); - //