From e138c6e09ecac25ebb9f25805434912372952427 Mon Sep 17 00:00:00 2001 From: GotPPay Date: Wed, 11 Apr 2018 10:42:06 +0200 Subject: [PATCH 1/2] improved code readability (comment from PR #18 --- web/src/components/IntentDetails.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/web/src/components/IntentDetails.js b/web/src/components/IntentDetails.js index ab24450..4452d35 100644 --- a/web/src/components/IntentDetails.js +++ b/web/src/components/IntentDetails.js @@ -155,14 +155,16 @@ class IntentDetails extends Component { } handleQuestionEdit (e, index) { - if (e.length >= QUESTION_MAX_LENGTH || !/^[a-z,.' ]*$/i.test (e)) return; + 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}); } handleIntentExplanationEdit (e, index) { - if (e.length >= INTENT_EXPLANATION_MAX_LENGTH || !/^[a-z,.' ]*$/i.test (e)) + const isExplanationInvalid = e.length >= INTENT_EXPLANATION_MAX_LENGTH || !/^[a-z,.' ]*$/i.test (e); + if (isExplanationInvalid) return; let newIntent = this.state.intent; newIntent.intentExplanation = e; @@ -170,21 +172,24 @@ class IntentDetails extends Component { } handleAnswerEdit (e) { - if (e.length >= ANSWER_MAX_LENGTH || !/^[a-z,.' ]*$/i.test (e)) return; + 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}); } handleAnswerSourceEdit (e) { - if (e.length >= ANSWER_MAX_LENGTH) return; + const isAnswerSourceInvalid = e.length >= ANSWER_MAX_LENGTH; + if (isAnswerSourceInvalid) return; let newIntent = this.state.intent; newIntent.externalAnswerSource = e; this.setState ({intent: newIntent}); } handleIntentNameEdit (e) { - if (e.length >= INTENT_NAME_MAX_LENGTH || !/^[a-z]*$/i.test (e)) return; + 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}); From 4ac728472416e636335131d0d8ba03779eaaf0a5 Mon Sep 17 00:00:00 2001 From: GotPPay Date: Wed, 11 Apr 2018 10:49:12 +0200 Subject: [PATCH 2/2] improved code readability (comment from PR #18) --- web/src/components/Contact.js | 3 ++- web/src/components/LaunchRequest.js | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/web/src/components/Contact.js b/web/src/components/Contact.js index 669945b..4d8e141 100644 --- a/web/src/components/Contact.js +++ b/web/src/components/Contact.js @@ -40,7 +40,8 @@ class Contact extends Component { } handleEmailEdit(e){ - if (e.length === EMAIL_MAX_LENGTH) return; + const isEmailInvalid = e.length >= EMAIL_MAX_LENGTH; + if (isEmailInvalid) return; this.setState({contactEmail: e}); } } diff --git a/web/src/components/LaunchRequest.js b/web/src/components/LaunchRequest.js index a5337ea..a141dc6 100644 --- a/web/src/components/LaunchRequest.js +++ b/web/src/components/LaunchRequest.js @@ -52,12 +52,14 @@ class LaunchRequest extends Component { } handleNameEdit(e){ - if (e.length === INVOCATION_NAME_MAX_LENGTH || !(/^[a-z,.' ]*$/.test(e))) return; + const isInvocationNameInvalid = e.length === INVOCATION_NAME_MAX_LENGTH || !(/^[a-z,.' ]*$/.test(e)); + if (isInvocationNameInvalid) return; this.setState({invocationName: e}); } handleAnswerEdit(e){ - if (e.length === INVOCATION_ANSWER_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e))) return; + const isInvocationAnswerInvalid = e.length === INVOCATION_ANSWER_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e)); + if (isInvocationAnswerInvalid) return; this.setState({invocationAnswer: e}); } }