fix state caching bugs in RoomHeader

pull/21833/head
Matthew Hodgson 2016-03-21 00:39:33 +00:00
parent eadd2a522f
commit 31ed7b9dd7
1 changed files with 19 additions and 11 deletions

View File

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