From 04f35e52f67ef7249c58bcf52c4b465c3dd4ea50 Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Mon, 5 Apr 2021 13:59:39 -0400 Subject: [PATCH] Finish first version of idea comparator --- src/index.css | 107 +++++++++++++++++++++++-------------------------- src/index.js | 109 ++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 143 insertions(+), 73 deletions(-) diff --git a/src/index.css b/src/index.css index 4c292d5..ef92624 100644 --- a/src/index.css +++ b/src/index.css @@ -1,81 +1,76 @@ body { - color: #777; + color: #777; } /* The content `
` is where all your content goes. */ .content { - margin: 0 auto; - padding: 0 2em; - max-width: 800px; - margin-bottom: 50px; - line-height: 1.6em; + margin: 0 auto; + padding: 0 2em; + max-width: 800px; + margin-bottom: 50px; + line-height: 1.6em; } .header { - margin: 0; - color: #333; - text-align: center; - padding: 2.5em 2em 0; - border-bottom: 1px solid #eee; - } - .header h1 { - margin: 0.2em 0; - font-size: 3em; - font-weight: 300; - } - .header h2 { - font-weight: 300; - color: #ccc; - padding: 0; - margin-top: 0; - } - -.content-subhead { - margin: 50px 0 20px 0; - font-weight: 300; - color: #888; + margin: 0; + color: #333; + text-align: center; + padding: 2.5em 2em 0; + border-bottom: 1px solid #eee; +} +.header h1 { + margin: 0.2em 0; + font-size: 3em; + font-weight: 300; +} +.header h2 { + font-weight: 300; + color: #ccc; + padding: 0; + margin-top: 0; } -.board-row:after { - clear: both; - content: ""; - display: table; +.content-subhead { + margin: 50px 0 20px 0; + font-weight: 300; + color: #888; } .space-1 { margin-top: 1em; } -.square { - background: #fff; - border: 1px solid #999; - float: left; - font-size: 24px; - font-weight: bold; - line-height: 34px; - height: 34px; - margin-right: -1px; - margin-top: -1px; - padding: 0; - text-align: center; - width: 34px; -} - -.square:focus { - outline: none; -} - .kbd-navigation .square:focus { background: #ddd; } -.game { - display: flex; - flex-direction: row; +.button-success, +.button-error, +.button-warning, +.button-secondary { + color: white; + border-radius: 4px; + text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2); } -.game-info { - margin-left: 20px; +.button-success { + background: rgb(28, 184, 65); + /* this is a green */ +} + +.button-error { + background: rgb(202, 60, 60); + /* this is a maroon */ +} + +.button-warning { + background: rgb(223, 117, 20); + /* this is an orange */ +} + +.button-secondary { + background: rgb(66, 184, 221); + /* this is a light blue */ } diff --git a/src/index.js b/src/index.js index 52af26d..488cd99 100644 --- a/src/index.js +++ b/src/index.js @@ -11,10 +11,11 @@ function shuffleArray(array) { } class Decision { - constructor(choiceA, choiceB) { - this.choiceA = choiceA; - this.choiceB = choiceB; - this.result = null; + constructor(indexA, indexB, choices) { + this.indexA = indexA; + this.indexB = indexB; + this.choiceA = choices[indexA]; + this.choiceB = choices[indexB]; } static createDecisions(choices) { @@ -22,7 +23,7 @@ class Decision { for (var i = 0; i < choices.length; i++) { for (var j = 0; j < choices.length; j++) { if (i !== j) { - let d = new Decision(choices[i], choices[j]); + let d = new Decision(i, j, choices); decisions.push(d); } } @@ -39,13 +40,16 @@ class Options extends React.Component { choicesText: null, choices: [], decisions: null, - warnings: null, + decisionsMade: null, + currentDecision: null, }; } startChoosing() { this.setState({ decisions: Decision.createDecisions(this.state.choices), + decisionsMade: [], + currentDecision: 0, }); } @@ -64,20 +68,49 @@ class Options extends React.Component { }); } - renderChoosing() { - const decisions = this.state.decisions; - const decisionsToRender = decisions.map((decision, index) => { - return ( -
  • - {decision.choiceA} - {decision.choiceB} -
  • - ); + makeChoice(i) { + this.setState({ + currentDecision: this.state.currentDecision + 1, + decisionsMade: this.state.decisionsMade.concat([i]), }); + } + + renderChoosing() { + const current = this.state.currentDecision; + const decision = this.state.decisions[current]; return (
    -
    -
      {decisionsToRender}
    +
    +
    +

    {decision.choiceA}

    +
    +
    +
    +

    {decision.choiceB}

    +
    +
    +
    + +
    + +
    +
    ); @@ -152,11 +185,53 @@ class Options extends React.Component { ); } + renderResult() { + let choices = this.state.choices.map((choice, index) => { + return { + choice: choice, + count: 0, + }; + }); + + for (const i of this.state.decisionsMade) { + if (i !== -1) { + choices[i].count += 1; + } + } + + choices.sort((a, b) => b.count - a.count); + + let choicesToRender = choices.map((choice, index) => { + return ( + + {choice.choice} + {choice.count} + + ); + }); + + return ( +
    + + + + + + + + {choicesToRender} +
    ChoiceCount
    +
    + ); + } + render() { if (!this.state.decisions) { return this.renderSpecifyChoices(); - } else { + } else if (this.state.currentDecision < this.state.decisions.length) { return this.renderChoosing(); + } else { + return this.renderResult(); } } }