From 896d8916b8151994e130022d2683a83ca82bc9b8 Mon Sep 17 00:00:00 2001 From: Dominique Date: Wed, 11 Dec 2019 16:52:33 -0800 Subject: [PATCH 1/5] finished form --- src/components/Game.js | 20 ++++- src/components/PlayerSubmissionForm.js | 118 ++++++++++++++++++++++--- 2 files changed, 126 insertions(+), 12 deletions(-) diff --git a/src/components/Game.js b/src/components/Game.js index e99f985a..6b07775b 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -8,6 +8,23 @@ class Game extends Component { constructor(props) { super(props); + + this.state = { + playerInput: [], + } + + } + + + addPlayerInput = (newInput) => { + const {playerInput} = this.state + console.log(playerInput) + + playerInput.push(newInput); + + this.setState({ + playerInput + }) } render() { @@ -34,7 +51,7 @@ class Game extends Component { - + @@ -44,6 +61,7 @@ class Game extends Component { } const FIELDS = [ + // Can I use this FIELDS globally? Like can I use it in the state of PlayerSubmissionForm? "The", { key: 'adj1', diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index 1de05095..ff64ea20 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -5,25 +5,121 @@ class PlayerSubmissionForm extends Component { constructor(props) { super(props); + + this.state = { + adj1: '', + noun1: '', + adv: '', + verb: '', + adj2: '', + noun2: '', + } } - render() { + resetState = () => { + this.setState({ + adj1: '', + noun1: '', + adv: '', + verb: '', + adj2: '', + noun2: '', + }); + } + + + onFormChange = (event) => { + + //target is the html element itself. You can do + //event.target.id to see specifics in the html target. + + const field = event.target.id; + + const value = event.target.value; + // describe what the event.target syntax is doing exactly + + const updatedState = {}; + updatedState[field] = value; + + this.setState(updatedState); + } + onSubmit = (event) => { + + event.preventDefault(); + // this prevents the page from refreshing so you don't loose the state + // what does this do again? + + const {adj1, noun1, adv, verb, adj2, noun2} = this.state; + + // what is this saying exactly? + + this.props.addPlayerInputCallback(this.state); + this.resetState(); + } + + + render() { + let count = 0 return (
-

Player Submission Form for Player #{ }

+

Player Submission Form for Player #{count}

+ {console.log(count)} -
+
- - { - // Put your form inputs here... We've put in one below as an example - } - - +
The
+ + + + + +
the
+
From d687ea0274ac403400e370eb92a1ebed56acf239 Mon Sep 17 00:00:00 2001 From: Dominique Date: Wed, 11 Dec 2019 20:31:59 -0800 Subject: [PATCH 2/5] wave 1 finished --- src/components/FinalPoem.js | 2 ++ src/components/Game.js | 8 +++----- src/components/PlayerSubmissionForm.js | 11 +++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js index d516184e..5784ccf8 100644 --- a/src/components/FinalPoem.js +++ b/src/components/FinalPoem.js @@ -2,6 +2,8 @@ import React from 'react'; import './FinalPoem.css'; const FinalPoem = (props) => { + + console.log(props) return (
diff --git a/src/components/Game.js b/src/components/Game.js index 6b07775b..e9284fdf 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -12,13 +12,11 @@ class Game extends Component { this.state = { playerInput: [], } - } - addPlayerInput = (newInput) => { const {playerInput} = this.state - console.log(playerInput) + playerInput.push(newInput); @@ -51,10 +49,10 @@ class Game extends Component { - + -
); } diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index ff64ea20..1ea03589 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -14,6 +14,8 @@ class PlayerSubmissionForm extends Component { adj2: '', noun2: '', } + + } resetState = () => { @@ -60,14 +62,15 @@ class PlayerSubmissionForm extends Component { render() { - let count = 0 + + return (
-

Player Submission Form for Player #{count}

- {console.log(count)} +

Player Submission Form for Player #{this.props.playerNumber}

- + +
The
Date: Thu, 12 Dec 2019 16:53:54 -0800 Subject: [PATCH 3/5] finished wave 2 --- src/components/FinalPoem.js | 18 ++++++++++++++++-- src/components/Game.js | 8 ++++++-- src/components/PlayerSubmissionForm.js | 5 ++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js index 5784ccf8..1736163a 100644 --- a/src/components/FinalPoem.js +++ b/src/components/FinalPoem.js @@ -3,7 +3,20 @@ import './FinalPoem.css'; const FinalPoem = (props) => { - console.log(props) + const submissions = props.finalPlayerInput; + // console.log(finalPoem); + // why does this show in the console when I hit "submit" button? + + + const poemContent = submissions.map((line, i) => { + return

{ line }

; + // why can I use tags here? + }); + + const onFinalClick = (event) => { + return submissions + // can't render an object, only components which render itself. YOu can't render an array. + }; return (
@@ -13,7 +26,8 @@ const FinalPoem = (props) => {
- + +
    {poemContent}
); diff --git a/src/components/Game.js b/src/components/Game.js index e9284fdf..33573f27 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -17,10 +17,12 @@ class Game extends Component { addPlayerInput = (newInput) => { const {playerInput} = this.state - playerInput.push(newInput); this.setState({ + // always change state through set state + // if I didn't have this, the state wouldn't be change, it would only + // change the local variable playerInput }) } @@ -52,7 +54,9 @@ class Game extends Component { - + + +
); } diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index 1ea03589..e3098e78 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -7,6 +7,7 @@ class PlayerSubmissionForm extends Component { super(props); this.state = { + adj1: '', noun1: '', adv: '', @@ -55,8 +56,10 @@ class PlayerSubmissionForm extends Component { const {adj1, noun1, adv, verb, adj2, noun2} = this.state; // what is this saying exactly? + + const newSubmission = `The ${adj1} ${adv} ${verb} the ${adj2} ${noun2}` - this.props.addPlayerInputCallback(this.state); + this.props.addPlayerInputCallback(newSubmission); this.resetState(); } From caeb5fb5b19d75d95bd0ad84782d009a512cce1f Mon Sep 17 00:00:00 2001 From: Dominique Date: Thu, 12 Dec 2019 21:21:28 -0800 Subject: [PATCH 4/5] hidden playsubmission form --- src/components/FinalPoem.js | 61 +++++++++++++------------- src/components/Game.js | 29 ++++++++---- src/components/PlayerSubmissionForm.js | 2 +- src/components/RecentSubmission.js | 28 +++++++++--- 4 files changed, 75 insertions(+), 45 deletions(-) diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js index 1736163a..5361d044 100644 --- a/src/components/FinalPoem.js +++ b/src/components/FinalPoem.js @@ -1,36 +1,37 @@ -import React from 'react'; +import React, { Component } from 'react'; import './FinalPoem.css'; -const FinalPoem = (props) => { - - const submissions = props.finalPlayerInput; - // console.log(finalPoem); - // why does this show in the console when I hit "submit" button? - - - const poemContent = submissions.map((line, i) => { - return

{ line }

; - // why can I use tags here? - }); - - const onFinalClick = (event) => { - return submissions - // can't render an object, only components which render itself. YOu can't render an array. - }; - - return ( -
-
-

Final Poem

- -
- -
- -
    {poemContent}
+class FinalPoem extends Component { + + constructor(props) { + super(props); + + this.state = { + isClicked: false + } + } + + render () { + const poemContent = this.props.finalPlayerInput.map((line, i) => { + return

{ line }

; + // why can I use tags here? + }); + + return ( +
+
+

Final Poem

+ +
+ +
+ {this.props.isPoemSubmitted ?
    {poemContent}
: } + + {/*
    {poemContent}
*/} +
-
- ); + ); + } } export default FinalPoem; diff --git a/src/components/Game.js b/src/components/Game.js index 33573f27..924f9849 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -11,9 +11,18 @@ class Game extends Component { this.state = { playerInput: [], + isPoemSubmitted: false, } } + + onPoemSubmittedCallback = () => { + this.setState({ + isPoemSubmitted: true, + }) + } + + addPlayerInput = (newInput) => { const {playerInput} = this.state @@ -37,6 +46,12 @@ class Game extends Component { } }).join(" "); + const recentSubmission = + + const playerSubmissionForm = + return (

Game

@@ -48,15 +63,13 @@ class Game extends Component {

{ exampleFormat }

+ + {this.state.isPoemSubmitted ?
: recentSubmission} + {this.state.isPoemSubmitted ?
: playerSubmissionForm} - - - - - - - +
); } diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index e3098e78..2d7bdbc3 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -57,7 +57,7 @@ class PlayerSubmissionForm extends Component { // what is this saying exactly? - const newSubmission = `The ${adj1} ${adv} ${verb} the ${adj2} ${noun2}` + const newSubmission = `The ${adj1} ${noun1} ${adv} ${verb} the ${adj2} ${noun2} .` this.props.addPlayerInputCallback(newSubmission); this.resetState(); diff --git a/src/components/RecentSubmission.js b/src/components/RecentSubmission.js index 663da34b..b779b967 100644 --- a/src/components/RecentSubmission.js +++ b/src/components/RecentSubmission.js @@ -2,12 +2,28 @@ import React from 'react'; import './RecentSubmission.css'; const RecentSubmission = (props) => { - return ( -
-

The Most Recent Submission

-

{ }

-
- ); + + if (props.latestSubmission) { + return ( + +
+

The Most Recent Submission

+

{props.latestSubmission}

+
+ ); + } else { + return ( +
+ ) + } + + // return ( + + //
+ //

The Most Recent Submission

+ //

{ props.latestSubmission }

+ //
+ // ); } export default RecentSubmission; From 3fdc690e2a1508b884b6aac8c6a7c5c5ac4c5e36 Mon Sep 17 00:00:00 2001 From: Dominique Date: Thu, 12 Dec 2019 22:43:58 -0800 Subject: [PATCH 5/5] finished project --- src/components/FinalPoem.js | 54 +++++++++++++------------ src/components/PlayerSubmissionForm.css | 1 + src/components/PlayerSubmissionForm.js | 25 ++++++++---- src/components/RecentSubmission.js | 11 ++--- 4 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js index 5361d044..bccaf6b9 100644 --- a/src/components/FinalPoem.js +++ b/src/components/FinalPoem.js @@ -1,37 +1,39 @@ -import React, { Component } from 'react'; +import React from 'react'; import './FinalPoem.css'; - -class FinalPoem extends Component { - - constructor(props) { - super(props); - - this.state = { - isClicked: false - } - } - - render () { - const poemContent = this.props.finalPlayerInput.map((line, i) => { +import PropTypes from 'prop-types'; + +const FinalPoem = (props) => { + + const revealPoemButton = +
+ +
; + + + const poemContent = props.finalPlayerInput.map((line, i) => { return

{ line }

; - // why can I use tags here? }); - return ( -
-
-

Final Poem

+ const revealPoem = +
+

Final Poem

+ {poemContent} +
; -
+ const content = props.isPoemSubmitted ? revealPoem : revealPoemButton -
- {this.props.isPoemSubmitted ?
    {poemContent}
: } - - {/*
    {poemContent}
*/} -
+ return ( +
+ {content}
); - } +} + +FinalPoem.propTypes = { + onPoemSubmittedCallback: PropTypes.isRequired, + isPoemSubmitted: PropTypes.isRequired, + finalPlayerInput: PropTypes.arrayOf(String), } export default FinalPoem; diff --git a/src/components/PlayerSubmissionForm.css b/src/components/PlayerSubmissionForm.css index 7cded5d9..5feb49ec 100644 --- a/src/components/PlayerSubmissionForm.css +++ b/src/components/PlayerSubmissionForm.css @@ -35,6 +35,7 @@ background-color: #FFE9E9; } + .PlayerSubmissionForm__input--invalid::placeholder { color: black; } diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index 2d7bdbc3..aa627c9c 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -1,5 +1,6 @@ import React, { Component } from 'react'; import './PlayerSubmissionForm.css'; +import PropTypes from 'prop-types'; class PlayerSubmissionForm extends Component { @@ -14,9 +15,9 @@ class PlayerSubmissionForm extends Component { verb: '', adj2: '', noun2: '', - } - + }; + this.isValid = false } resetState = () => { @@ -45,6 +46,9 @@ class PlayerSubmissionForm extends Component { updatedState[field] = value; this.setState(updatedState); + this.isValid = true + + } onSubmit = (event) => { @@ -79,7 +83,7 @@ class PlayerSubmissionForm extends Component { { @@ -16,14 +17,10 @@ const RecentSubmission = (props) => {
) } +} - // return ( - - //
- //

The Most Recent Submission

- //

{ props.latestSubmission }

- //
- // ); +RecentSubmission.propTypes = { + latestSubmission: PropTypes.string } export default RecentSubmission;