From 5a1d87815062ba87306029606246d6df0cddec6c Mon Sep 17 00:00:00 2001 From: GotPPay Date: Sun, 15 Apr 2018 16:28:19 +0200 Subject: [PATCH] flip logic (comment from PR #18) --- web/src/components/Contact.js | 7 ++-- web/src/components/IntentDetails.js | 56 +++++++++++++++-------------- web/src/components/LaunchRequest.js | 14 ++++---- 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/web/src/components/Contact.js b/web/src/components/Contact.js index 4d8e141..a292b91 100644 --- a/web/src/components/Contact.js +++ b/web/src/components/Contact.js @@ -40,9 +40,10 @@ class Contact extends Component { } handleEmailEdit(e){ - const isEmailInvalid = e.length >= EMAIL_MAX_LENGTH; - if (isEmailInvalid) return; - this.setState({contactEmail: e}); + const isEmailValid = e.length < EMAIL_MAX_LENGTH; + if (isEmailValid){ + this.setState({contactEmail: e}); + } } } diff --git a/web/src/components/IntentDetails.js b/web/src/components/IntentDetails.js index 4452d35..89e95db 100644 --- a/web/src/components/IntentDetails.js +++ b/web/src/components/IntentDetails.js @@ -155,44 +155,48 @@ class IntentDetails extends Component { } handleQuestionEdit (e, index) { - const isQuestionInvalid = e.length >= QUESTION_MAX_LENGTH || !/^[a-z,.' ]*$/i.test (e); - if (isQuestionInvalid) return; - let newIntent = this.state.intent; - newIntent.questions[index] = e; - this.setState ({intent: newIntent}); + const isQuestionValid = e.length < QUESTION_MAX_LENGTH && /^[a-z,.' ]*$/i.test (e); + if (isQuestionValid){ + let newIntent = this.state.intent; + newIntent.questions[index] = e; + this.setState ({intent: newIntent}); + } } handleIntentExplanationEdit (e, index) { - const isExplanationInvalid = e.length >= INTENT_EXPLANATION_MAX_LENGTH || !/^[a-z,.' ]*$/i.test (e); - if (isExplanationInvalid) - return; - let newIntent = this.state.intent; - newIntent.intentExplanation = e; - this.setState ({intent: newIntent}); + const isExplanationValid = e.length < INTENT_EXPLANATION_MAX_LENGTH && /^[a-z,.' ]*$/i.test (e); + if (isExplanationValid){ + let newIntent = this.state.intent; + newIntent.intentExplanation = e; + this.setState ({intent: newIntent}); + } } handleAnswerEdit (e) { - const isAnswerInvalid = e.length >= ANSWER_MAX_LENGTH || !/^[a-z,.' ]*$/i.test (e); - if (isAnswerInvalid) return; - let newIntent = this.state.intent; - newIntent.answer = e; - this.setState ({intent: newIntent}); + const isAnswerValid = e.length < ANSWER_MAX_LENGTH && /^[a-z,.' ]*$/i.test (e); + if (isAnswerValid){ + let newIntent = this.state.intent; + newIntent.answer = e; + this.setState ({intent: newIntent}); + } } handleAnswerSourceEdit (e) { - const isAnswerSourceInvalid = e.length >= ANSWER_MAX_LENGTH; - if (isAnswerSourceInvalid) return; - let newIntent = this.state.intent; - newIntent.externalAnswerSource = e; - this.setState ({intent: newIntent}); + const isAnswerSourceValid = e.length < ANSWER_MAX_LENGTH; + if (isAnswerSourceValid){ + let newIntent = this.state.intent; + newIntent.externalAnswerSource = e; + this.setState ({intent: newIntent}); + } } handleIntentNameEdit (e) { - const isIntentNameInvalid = e.length >= INTENT_NAME_MAX_LENGTH || !/^[a-z]*$/i.test (e); - if (isIntentNameInvalid) return; - let newIntent = this.state.intent; - newIntent.intentName = e; - this.setState ({intent: newIntent}); + const isIntentNameValid = e.length < INTENT_NAME_MAX_LENGTH && /^[a-z]*$/i.test (e); + if (isIntentNameValid){ + let newIntent = this.state.intent; + newIntent.intentName = e; + this.setState ({intent: newIntent}); + } } handleExternalSourceSave (answerType) { diff --git a/web/src/components/LaunchRequest.js b/web/src/components/LaunchRequest.js index a141dc6..6d4f555 100644 --- a/web/src/components/LaunchRequest.js +++ b/web/src/components/LaunchRequest.js @@ -52,15 +52,17 @@ class LaunchRequest extends Component { } handleNameEdit(e){ - const isInvocationNameInvalid = e.length === INVOCATION_NAME_MAX_LENGTH || !(/^[a-z,.' ]*$/.test(e)); - if (isInvocationNameInvalid) return; - this.setState({invocationName: e}); + const isInvocationNameValid = e.length < INVOCATION_NAME_MAX_LENGTH && (/^[a-z,.' ]*$/.test(e)); + if (isInvocationNameValid) { + this.setState({invocationName: e}); + } } handleAnswerEdit(e){ - const isInvocationAnswerInvalid = e.length === INVOCATION_ANSWER_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e)); - if (isInvocationAnswerInvalid) return; - this.setState({invocationAnswer: e}); + const isInvocationAnswerValid = e.length < INVOCATION_ANSWER_MAX_LENGTH && (/^[a-z,.' ]*$/i.test(e)); + if (isInvocationAnswerValid){ + this.setState({invocationAnswer: e}); + } } }