From 68d60aadd16ed48ebe701130a6360bbbcdcfb3c4 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 16 Jul 2015 17:24:33 +0100 Subject: [PATCH] Make Presets stateless --- skins/base/views/atoms/create_room/Presets.js | 4 ++-- skins/base/views/organisms/CreateRoom.js | 3 +-- src/controllers/atoms/create_room/Presets.js | 20 ------------------- src/controllers/organisms/CreateRoom.js | 7 +++---- 4 files changed, 6 insertions(+), 28 deletions(-) diff --git a/skins/base/views/atoms/create_room/Presets.js b/skins/base/views/atoms/create_room/Presets.js index 04e7d34d..271702b1 100644 --- a/skins/base/views/atoms/create_room/Presets.js +++ b/skins/base/views/atoms/create_room/Presets.js @@ -25,12 +25,12 @@ module.exports = React.createClass({ mixins: [PresetsController], onValueChanged: function(ev) { - this.setState({preset: ev.target.value}, this.props.onChange); + this.props.onChange(ev.target.value) }, render: function() { return ( - diff --git a/skins/base/views/organisms/CreateRoom.js b/skins/base/views/organisms/CreateRoom.js index fa6d55f2..ae250db9 100644 --- a/skins/base/views/organisms/CreateRoom.js +++ b/skins/base/views/organisms/CreateRoom.js @@ -58,8 +58,7 @@ module.exports = React.createClass({ return this.refs.user_selector.getUserIds(); }, - onPresetChanged: function() { - var preset = this.refs.presets.getPreset(); + onPresetChanged: function(preset) { switch (preset) { case PresetValues.PrivateChat: this.setState({ diff --git a/src/controllers/atoms/create_room/Presets.js b/src/controllers/atoms/create_room/Presets.js index 976c88db..bcc2f514 100644 --- a/src/controllers/atoms/create_room/Presets.js +++ b/src/controllers/atoms/create_room/Presets.js @@ -27,7 +27,6 @@ var Presets = { module.exports = { propTypes: { onChange: React.PropTypes.func, - default_preset: React.PropTypes.string, preset: React.PropTypes.string }, @@ -36,25 +35,6 @@ module.exports = { getDefaultProps: function() { return { 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; - }, }; diff --git a/src/controllers/organisms/CreateRoom.js b/src/controllers/organisms/CreateRoom.js index 6ba8247f..107e94b3 100644 --- a/src/controllers/organisms/CreateRoom.js +++ b/src/controllers/organisms/CreateRoom.js @@ -62,10 +62,9 @@ module.exports = { options.topic = this.state.topic; } - var preset = this.getPreset(); - if (preset) { - if (preset != PresetValues.Custom) { - options.preset = preset; + if (this.state.preset) { + if (this.state.preset != PresetValues.Custom) { + options.preset = this.state.preset; } else { options.initial_state = [ {