Merge pull request #1746 from matrix-org/luke/fix-room-settings-resets
Store component state for editorspull/21833/head
commit
46b8fb9a19
|
@ -29,13 +29,21 @@ module.exports = React.createClass({
|
||||||
room: PropTypes.object.isRequired,
|
room: PropTypes.object.isRequired,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
name: null,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
const room = this.props.room;
|
const room = this.props.room;
|
||||||
const name = room.currentState.getStateEvents('m.room.name', '');
|
const name = room.currentState.getStateEvents('m.room.name', '');
|
||||||
const myId = MatrixClientPeg.get().credentials.userId;
|
const myId = MatrixClientPeg.get().credentials.userId;
|
||||||
const defaultName = room.getDefaultRoomName(myId);
|
const defaultName = room.getDefaultRoomName(myId);
|
||||||
|
|
||||||
this._initialName = name ? name.getContent().name : '';
|
this.setState({
|
||||||
|
name: name ? name.getContent().name : '',
|
||||||
|
});
|
||||||
|
|
||||||
this._placeholderName = _t("Unnamed Room");
|
this._placeholderName = _t("Unnamed Room");
|
||||||
if (defaultName && defaultName !== 'Empty room') { // default name from JS SDK, needs no translation as we don't ever show it.
|
if (defaultName && defaultName !== 'Empty room') { // default name from JS SDK, needs no translation as we don't ever show it.
|
||||||
|
@ -44,7 +52,13 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
getRoomName: function() {
|
getRoomName: function() {
|
||||||
return this.refs.editor.getValue();
|
return this.state.name;
|
||||||
|
},
|
||||||
|
|
||||||
|
_onValueChanged: function(value, shouldSubmit) {
|
||||||
|
this.setState({
|
||||||
|
name: value,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
@ -57,7 +71,8 @@ module.exports = React.createClass({
|
||||||
placeholderClassName="mx_RoomHeader_placeholder"
|
placeholderClassName="mx_RoomHeader_placeholder"
|
||||||
placeholder={this._placeholderName}
|
placeholder={this._placeholderName}
|
||||||
blurToCancel={false}
|
blurToCancel={false}
|
||||||
initialValue={this._initialName}
|
initialValue={this.state.name}
|
||||||
|
onValueChanged={this._onValueChanged}
|
||||||
dir="auto" />
|
dir="auto" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -28,26 +28,41 @@ module.exports = React.createClass({
|
||||||
room: PropTypes.object.isRequired,
|
room: PropTypes.object.isRequired,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
topic: null,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
const room = this.props.room;
|
const room = this.props.room;
|
||||||
const topic = room.currentState.getStateEvents('m.room.topic', '');
|
const topic = room.currentState.getStateEvents('m.room.topic', '');
|
||||||
this._initialTopic = topic ? topic.getContent().topic : '';
|
this.setState({
|
||||||
|
topic: topic ? topic.getContent().topic : '',
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getTopic: function() {
|
getTopic: function() {
|
||||||
return this.refs.editor.getValue();
|
return this.state.topic;
|
||||||
|
},
|
||||||
|
|
||||||
|
_onValueChanged: function(value) {
|
||||||
|
this.setState({
|
||||||
|
topic: value,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
const EditableText = sdk.getComponent("elements.EditableText");
|
const EditableText = sdk.getComponent("elements.EditableText");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EditableText ref="editor"
|
<EditableText
|
||||||
className="mx_RoomHeader_topic mx_RoomHeader_editable"
|
className="mx_RoomHeader_topic mx_RoomHeader_editable"
|
||||||
placeholderClassName="mx_RoomHeader_placeholder"
|
placeholderClassName="mx_RoomHeader_placeholder"
|
||||||
placeholder={_t("Add a topic")}
|
placeholder={_t("Add a topic")}
|
||||||
blurToCancel={false}
|
blurToCancel={false}
|
||||||
initialValue={this._initialTopic}
|
initialValue={this.state.topic}
|
||||||
|
onValueChanged={this._onValueChanged}
|
||||||
dir="auto" />
|
dir="auto" />
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue