fix state caching bugs in RoomHeader

This commit is contained in:
Matthew Hodgson 2016-03-21 00:39:33 +00:00
parent eadd2a522f
commit 31ed7b9dd7

View file

@ -53,8 +53,17 @@ module.exports = React.createClass({
return {}; return {};
}, },
componentWillMount: function() {
this._recalculateState();
},
componentWillReceiveProps: function(newProps) { componentWillReceiveProps: function(newProps) {
if (this.props.room !== newProps.room && newProps.editing) { if (this.props.room !== newProps.room) {
this._recalculateState();
}
},
_recalculateState: function() {
var topic = this.props.room.currentState.getStateEvents('m.room.topic', ''); var topic = this.props.room.currentState.getStateEvents('m.room.topic', '');
var name = this.props.room.currentState.getStateEvents('m.room.name', ''); var name = this.props.room.currentState.getStateEvents('m.room.name', '');
@ -63,7 +72,6 @@ module.exports = React.createClass({
defaultName: this.props.room.getDefaultRoomName(MatrixClientPeg.get().credentials.userId), defaultName: this.props.room.getDefaultRoomName(MatrixClientPeg.get().credentials.userId),
topic: topic ? topic.getContent().topic : '', topic: topic ? topic.getContent().topic : '',
}); });
}
}, },
componentDidUpdate: function() { componentDidUpdate: function() {
@ -224,8 +232,8 @@ module.exports = React.createClass({
onValueChanged={ this.onTopicChanged } onValueChanged={ this.onTopicChanged }
initialValue={ this.state.topic }/> initialValue={ this.state.topic }/>
} else { } else {
var topic = this.props.room ? this.props.room.currentState.getStateEvents('m.room.topic', '') : ''; if (this.state.topic)
if (topic) topic_el = <div className="mx_RoomHeader_topic" ref="topic" title={ topic.getContent().topic }>{ topic.getContent().topic }</div>; topic_el = <div className="mx_RoomHeader_topic" ref="topic" title={ this.state.topic }>{ this.state.topic }</div>;
} }
var roomAvatar = null; var roomAvatar = null;