From b530018dda141b2f32dcbbcb3e1333d36acad42d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 28 Jul 2015 11:06:19 +0200 Subject: [PATCH 1/2] remove unused components --- js/components/ascribe_forms/input_hidden.js | 39 ---------------- js/components/ascribe_forms/input_text.js | 46 ------------------- js/components/ascribe_forms/input_textarea.js | 41 ----------------- js/components/ascribe_forms/property.js | 1 - 4 files changed, 127 deletions(-) delete mode 100644 js/components/ascribe_forms/input_hidden.js delete mode 100644 js/components/ascribe_forms/input_text.js delete mode 100644 js/components/ascribe_forms/input_textarea.js diff --git a/js/components/ascribe_forms/input_hidden.js b/js/components/ascribe_forms/input_hidden.js deleted file mode 100644 index b6a8ac46..00000000 --- a/js/components/ascribe_forms/input_hidden.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -import React from 'react'; - -import AlertMixin from '../../mixins/alert_mixin'; - -let InputHidden = React.createClass({ - propTypes: { - submitted: React.PropTypes.bool, - value: React.PropTypes.string - }, - - mixins: [AlertMixin], - - getInitialState() { - return {value: this.props.value, - alerts: null // needed in AlertMixin - }; - }, - handleChange(event) { - this.setState({value: event.target.value}); - }, - render() { - let alerts = (this.props.submitted) ? null : this.state.alerts; - return ( -
- {alerts} - -
- ); - - } -}); - -export default InputHidden; \ No newline at end of file diff --git a/js/components/ascribe_forms/input_text.js b/js/components/ascribe_forms/input_text.js deleted file mode 100644 index 7f0ee5d0..00000000 --- a/js/components/ascribe_forms/input_text.js +++ /dev/null @@ -1,46 +0,0 @@ -'use strict'; - -import React from 'react'; - -import AlertMixin from '../../mixins/alert_mixin'; - -let InputText = React.createClass({ - propTypes: { - submitted: React.PropTypes.bool, - onBlur: React.PropTypes.func, - type: React.PropTypes.string, - required: React.PropTypes.string, - placeHolder: React.PropTypes.string - }, - - mixins: [AlertMixin], - - getInitialState() { - return {value: null, - alerts: null // needed in AlertMixin - }; - }, - - handleChange(event) { - this.setState({value: event.target.value}); - }, - - render() { - let className = 'form-control input-text-ascribe'; - let alerts = (this.props.submitted) ? null : this.state.alerts; - return ( -
- {alerts} - -
- ); - - } -}); - -export default InputText; \ No newline at end of file diff --git a/js/components/ascribe_forms/input_textarea.js b/js/components/ascribe_forms/input_textarea.js deleted file mode 100644 index 2c5ab40a..00000000 --- a/js/components/ascribe_forms/input_textarea.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -import React from 'react'; - -import AlertMixin from '../../mixins/alert_mixin'; - -let InputTextArea = React.createClass({ - propTypes: { - submitted: React.PropTypes.bool, - required: React.PropTypes.string, - defaultValue: React.PropTypes.string - }, - - mixins: [AlertMixin], - - getInitialState() { - return { - value: this.props.defaultValue, - alerts: null // needed in AlertMixin - }; - }, - handleChange(event) { - this.setState({value: event.target.value}); - }, - render() { - let className = 'form-control input-text-ascribe textarea-ascribe-message'; - - let alerts = (this.props.submitted) ? null : this.state.alerts; - return ( -
- {alerts} - -
- ); - } -}); - -export default InputTextArea; \ No newline at end of file diff --git a/js/components/ascribe_forms/property.js b/js/components/ascribe_forms/property.js index 93a32baa..c37d219d 100644 --- a/js/components/ascribe_forms/property.js +++ b/js/components/ascribe_forms/property.js @@ -158,7 +158,6 @@ let Property = React.createClass({ renderChildren() { return ReactAddons.Children.map(this.props.children, (child) => { return ReactAddons.addons.cloneWithProps(child, { - value: this.state.value, onChange: this.handleChange, onFocus: this.handleFocus, onBlur: this.handleBlur, From 09ce4de29dce2d2821f6f79f6ce8141030ca3608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 28 Jul 2015 12:03:45 +0200 Subject: [PATCH 2/2] refactor input checkbox --- js/components/ascribe_forms/form_signup.js | 3 +- js/components/ascribe_forms/input_checkbox.js | 38 +++++++++++-------- js/components/ascribe_forms/property.js | 3 ++ js/components/settings_container.js | 2 +- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/js/components/ascribe_forms/form_signup.js b/js/components/ascribe_forms/form_signup.js index dc2a6cdb..5f6a3c79 100644 --- a/js/components/ascribe_forms/form_signup.js +++ b/js/components/ascribe_forms/form_signup.js @@ -123,7 +123,8 @@ let SignupForm = React.createClass({ name="terms" className="ascribe-settings-property-collapsible-toggle" style={{paddingBottom: 0}}> - + {' ' + getLangText('I agree to the Terms of Service') + ' '} ( diff --git a/js/components/ascribe_forms/input_checkbox.js b/js/components/ascribe_forms/input_checkbox.js index 46f4eb78..b1733d08 100644 --- a/js/components/ascribe_forms/input_checkbox.js +++ b/js/components/ascribe_forms/input_checkbox.js @@ -4,35 +4,40 @@ import React from 'react'; let InputCheckbox = React.createClass({ propTypes: { - required: React.PropTypes.string.isRequired, - defaultValue: React.PropTypes.bool, + required: React.PropTypes.bool, + defaultChecked: React.PropTypes.bool, children: React.PropTypes.oneOfType([ React.PropTypes.arrayOf(React.PropTypes.element), React.PropTypes.element ]).isRequired }, - getDefaultProps() { - return { - required: 'required' - }; - }, getInitialState() { return { - //show: false - value: this.props.defaultValue + value: this.props.defaultChecked }; }, - onChange: function(event) { - let newValue = !this.state.value; - event.target.value = newValue; - this.props.onChange(event); - event.stopPropagation(); - this.setState({value: newValue}); + componentDidMount() { + this.props.onChange({ + target: { + value: this.state.value + } + }); + }, + + onChange() { + let value = !this.refs.checkbox.getDOMNode().checked; + this.setState({value: value}); + this.props.onChange({ + target: { + value: value + } + }); }, render() { + console.log(this.state.value); return ( @@ -40,7 +45,8 @@ let InputCheckbox = React.createClass({ type="checkbox" ref="checkbox" onChange={this.onChange} - checked={this.state.value}/> + checked={this.state.value} + defaultChecked={this.props.defaultChecked}/> {this.props.children} diff --git a/js/components/ascribe_forms/property.js b/js/components/ascribe_forms/property.js index c37d219d..8333a8bf 100644 --- a/js/components/ascribe_forms/property.js +++ b/js/components/ascribe_forms/property.js @@ -39,6 +39,9 @@ let Property = React.createClass({ getInitialState() { return { + // Please don't confuse initialValue with react's defaultValue. + // initialValue is set by us to ensure that a user can reset a specific + // property (after editing) to its initial value initialValue: null, value: null, isFocused: false, diff --git a/js/components/settings_container.js b/js/components/settings_container.js index 90d51506..c414f10f 100644 --- a/js/components/settings_container.js +++ b/js/components/settings_container.js @@ -115,7 +115,7 @@ let AccountSettings = React.createClass({ className="ascribe-settings-property-collapsible-toggle" style={{paddingBottom: 0}}> + defaultChecked={this.state.currentUser.profile.hash_locally}> {' ' + getLangText('Enable hash option for slow connections. ' + 'Computes and uploads a hash of the work instead.')}