From 9deb6f2c6a08cd33af0bbe16e4157d9216144bcc Mon Sep 17 00:00:00 2001 From: RujitRaval Date: Mon, 13 Jan 2020 12:16:00 -0500 Subject: [PATCH 1/3] Show message conditionally --- src/ComfortIssues.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ComfortIssues.js b/src/ComfortIssues.js index b3aacc522..c08a09e59 100644 --- a/src/ComfortIssues.js +++ b/src/ComfortIssues.js @@ -8,6 +8,8 @@ export default class ComfortIssues extends React.Component { this.state = { answerIds: this.props.answer, }; + // AnswerId for 'THEY DON'T COMPLAIN AT ALL' option + this.noComplains = 31 this.names = { tooHot: 'They complain it\'s too hot', tooCold: 'They complain it\'s too cold', @@ -32,17 +34,23 @@ export default class ComfortIssues extends React.Component { chooseAnswer = (answerId) => { let answerIds = this.state.answerIds - if (answerIds.includes(answerId)) { - answerIds = answerIds.filter(id => id !== answerId); - } else { - answerIds.push(answerId); + if (answerId === this.noComplains) { + answerIds = answerIds.includes(answerId) ? [] : [answerId]; + } + else { + answerIds = answerIds.filter(id => id !== this.noComplains); + if (answerIds.includes(answerId)) { + answerIds = answerIds.filter(id => id !== answerId); + } else { + answerIds.push(answerId); + } } this.setState({ answerIds }); } render() { let message = ""; - if (this.state.answerIds.length > 0) { + if (!this.state.answerIds.includes(this.noComplains)) { message = (
  -- GitLab From 59360259c7d2f6a1434162a92208c894be8bc955 Mon Sep 17 00:00:00 2001 From: RujitRaval Date: Mon, 13 Jan 2020 14:06:44 -0500 Subject: [PATCH 2/3] Solve button enabled issue and display message issue --- src/ComfortIssues.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/ComfortIssues.js b/src/ComfortIssues.js index c08a09e59..5f3a8395c 100644 --- a/src/ComfortIssues.js +++ b/src/ComfortIssues.js @@ -50,7 +50,7 @@ export default class ComfortIssues extends React.Component { render() { let message = ""; - if (!this.state.answerIds.includes(this.noComplains)) { + if (!this.state.answerIds.includes(this.noComplains) && this.state.answerIds.length > 0) { message = (
  @@ -104,12 +104,7 @@ export default class ComfortIssues extends React.Component { className="button" onClick={this.nextQuestion} disabled={ - this.state.tooCold === false && - this.state.tooHot === false && - this.state.windowsOpen === false && - this.state.spaceHeaters === false && - this.state.draft === false && - this.state.noComplaint === false + this.state.answerIds.length < 1 } > Continue > -- GitLab From e4d872551a0d9828bbb70dd9147364a64d43f69d Mon Sep 17 00:00:00 2001 From: RujitRaval Date: Mon, 13 Jan 2020 14:45:08 -0500 Subject: [PATCH 3/3] Change constant name --- src/ComfortIssues.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ComfortIssues.js b/src/ComfortIssues.js index 5f3a8395c..61019ea50 100644 --- a/src/ComfortIssues.js +++ b/src/ComfortIssues.js @@ -9,7 +9,7 @@ export default class ComfortIssues extends React.Component { answerIds: this.props.answer, }; // AnswerId for 'THEY DON'T COMPLAIN AT ALL' option - this.noComplains = 31 + this.noComplaints = 31 this.names = { tooHot: 'They complain it\'s too hot', tooCold: 'They complain it\'s too cold', @@ -34,11 +34,11 @@ export default class ComfortIssues extends React.Component { chooseAnswer = (answerId) => { let answerIds = this.state.answerIds - if (answerId === this.noComplains) { + if (answerId === this.noComplaints) { answerIds = answerIds.includes(answerId) ? [] : [answerId]; } else { - answerIds = answerIds.filter(id => id !== this.noComplains); + answerIds = answerIds.filter(id => id !== this.noComplaints); if (answerIds.includes(answerId)) { answerIds = answerIds.filter(id => id !== answerId); } else { @@ -50,7 +50,7 @@ export default class ComfortIssues extends React.Component { render() { let message = ""; - if (!this.state.answerIds.includes(this.noComplains) && this.state.answerIds.length > 0) { + if (!this.state.answerIds.includes(this.noComplaints) && this.state.answerIds.length > 0) { message = (
  -- GitLab