From 3e170fc7f49602be396063a4dc4dca87818fed63 Mon Sep 17 00:00:00 2001 From: "Ilya Ig. Petrov" Date: Sat, 17 Jun 2017 20:43:08 +0500 Subject: [PATCH] Validate on change, not on switch --- .../options/src/components/ProxyEditor.js | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ProxyEditor.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ProxyEditor.js index ddec6e3..f932ce8 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ProxyEditor.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ProxyEditor.js @@ -366,11 +366,15 @@ export default function getProxyEditor(theState) { super(props); this.state = getInitState(); + this.resetState = linkEvent(this, this.resetState); } resetState(that, event) { + if (that.state.ifHasErrors) { + that.props.funs.setStatusTo(''); // Clear errors + } that.setState(getInitState()); event.preventDefault(); @@ -417,28 +421,32 @@ export default function getProxyEditor(theState) { handleModeSwitch(that, event) { - if (that.state.stashedExports !== false) { - const errors = that.getErrorsInStashedExports(); - if (errors) { - that.setState({ifHasErrors: true}); - that.props.funs.showErrors(...errors); - return; - } - that.props.setProxyStringRaw(that.state.stashedExports); + console.log('SWITCH!'); + if (that.state.ifHasErrors) { + return; } - that.setState({ - stashedExports: false, - ifHasErrors: false, - }); that.props.onSwitch(); } handleTextareaChange(that, event) { + console.log('CHANGE!'); that.setState({ stashedExports: normalizeProxyString(event.target.value), }); + const errors = that.getErrorsInStashedExports(); + if (errors) { + that.setState({ifHasErrors: true}); + that.props.funs.showErrors(...errors); + return; + } + // No errors. + that.props.setProxyStringRaw(that.state.stashedExports); + that.setState({ + stashedExports: false, + ifHasErrors: false, + }); } @@ -451,8 +459,6 @@ export default function getProxyEditor(theState) { render(props) { - const reset = linkEvent(this, this.resetState); - return (
@@ -463,8 +469,8 @@ export default function getProxyEditor(theState) { this.state.stashedExports === false ? 'Комментарии вырезаются!' : (this.state.ifHasErrors - ? (Сбросьте изменения или поправьте) - : (Сбросить изменения) + ? (Сбросьте изменения или поправьте) + : (Сбросить изменения) ) }