Make Presets stateless
This commit is contained in:
parent
aa1b763518
commit
68d60aadd1
|
@ -25,12 +25,12 @@ module.exports = React.createClass({
|
||||||
mixins: [PresetsController],
|
mixins: [PresetsController],
|
||||||
|
|
||||||
onValueChanged: function(ev) {
|
onValueChanged: function(ev) {
|
||||||
this.setState({preset: ev.target.value}, this.props.onChange);
|
this.props.onChange(ev.target.value)
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
return (
|
return (
|
||||||
<select className="mx_Presets" onChange={this.onValueChanged} value={this.state.preset}>
|
<select className="mx_Presets" onChange={this.onValueChanged} value={this.props.preset}>
|
||||||
<option value={this.Presets.PrivateChat}>Private Chat</option>
|
<option value={this.Presets.PrivateChat}>Private Chat</option>
|
||||||
<option value={this.Presets.PublicChat}>Public Chat</option>
|
<option value={this.Presets.PublicChat}>Public Chat</option>
|
||||||
<option value={this.Presets.Custom}>Custom</option>
|
<option value={this.Presets.Custom}>Custom</option>
|
||||||
|
|
|
@ -58,8 +58,7 @@ module.exports = React.createClass({
|
||||||
return this.refs.user_selector.getUserIds();
|
return this.refs.user_selector.getUserIds();
|
||||||
},
|
},
|
||||||
|
|
||||||
onPresetChanged: function() {
|
onPresetChanged: function(preset) {
|
||||||
var preset = this.refs.presets.getPreset();
|
|
||||||
switch (preset) {
|
switch (preset) {
|
||||||
case PresetValues.PrivateChat:
|
case PresetValues.PrivateChat:
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|
|
@ -27,7 +27,6 @@ var Presets = {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
propTypes: {
|
propTypes: {
|
||||||
onChange: React.PropTypes.func,
|
onChange: React.PropTypes.func,
|
||||||
default_preset: React.PropTypes.string,
|
|
||||||
preset: React.PropTypes.string
|
preset: React.PropTypes.string
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -36,25 +35,6 @@ module.exports = {
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
return {
|
return {
|
||||||
onChange: function() {},
|
onChange: function() {},
|
||||||
default_preset: Presets.PrivateChat,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState: function() {
|
|
||||||
return {
|
|
||||||
preset: this.props.preset || this.props.default_preset,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
componentWillReceiveProps: function(new_props) {
|
|
||||||
if (new_props.preset) {
|
|
||||||
this.setState({
|
|
||||||
preset: new_props.preset
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
getPreset: function() {
|
|
||||||
return this.state.preset;
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,10 +62,9 @@ module.exports = {
|
||||||
options.topic = this.state.topic;
|
options.topic = this.state.topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
var preset = this.getPreset();
|
if (this.state.preset) {
|
||||||
if (preset) {
|
if (this.state.preset != PresetValues.Custom) {
|
||||||
if (preset != PresetValues.Custom) {
|
options.preset = this.state.preset;
|
||||||
options.preset = preset;
|
|
||||||
} else {
|
} else {
|
||||||
options.initial_state = [
|
options.initial_state = [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue