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,19 +53,27 @@ module.exports = React.createClass({
return {}; return {};
}, },
componentWillReceiveProps: function(newProps) { componentWillMount: function() {
if (this.props.room !== newProps.room && newProps.editing) { this._recalculateState();
var topic = this.props.room.currentState.getStateEvents('m.room.topic', ''); },
var name = this.props.room.currentState.getStateEvents('m.room.name', '');
this.setState({ componentWillReceiveProps: function(newProps) {
name: name ? name.getContent().name : '', if (this.props.room !== newProps.room) {
defaultName: this.props.room.getDefaultRoomName(MatrixClientPeg.get().credentials.userId), this._recalculateState();
topic: topic ? topic.getContent().topic : '',
});
} }
}, },
_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() { componentDidUpdate: function() {
if (this.refs.topic) { if (this.refs.topic) {
linkifyElement(this.refs.topic, linkifyMatrix.options); linkifyElement(this.refs.topic, linkifyMatrix.options);
@ -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;