From ee048475634bc4f7eb68aa0114af98b5aa772348 Mon Sep 17 00:00:00 2001 From: Bitaman Date: Tue, 18 Jun 2019 16:22:39 -0700 Subject: [PATCH 1/2] added the form and callback function in game --- src/components/Game.js | 16 ++++- src/components/PlayerSubmissionForm.js | 93 ++++++++++++++++++++++++-- 2 files changed, 101 insertions(+), 8 deletions(-) diff --git a/src/components/Game.js b/src/components/Game.js index e99f985a..2a4c1185 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -8,8 +8,22 @@ class Game extends Component { constructor(props) { super(props); + this.state = { + submissions: [], + isSubmitted: false, + } } + addSubmission = (newSubmission)=> { + console.log(newSubmission) + let nextSubmission = this.state.submissions + nextSubmission.push(newSubmission) + this.setState({ + submissions: nextSubmission + }) + console.log(this.state.submissions) + + } render() { const exampleFormat = FIELDS.map((field) => { @@ -34,7 +48,7 @@ class Game extends Component { - + diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index 1de05095..14efaa4b 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -5,29 +5,108 @@ class PlayerSubmissionForm extends Component { constructor(props) { super(props); + this.state = { + adj1: '', + noun1: '', + adv: '', + verb: '', + adj2: '', + noun2: '', + count: 0, + } + } + onInputChange = (event) => { + const updatedState = {}; + + const field = event.target.name; + const value = event.target.value; + + updatedState[field] = value; + this.setState(updatedState); + } + onFormSubmit = (event) => { + event.preventDefault(); + + const newSubmission = { + adj1: this.state.adj1, + noun1: this.state.noun1, + adv: this.state.adv, + verb: this.state.verb, + adj2: this.state.adj2, + noun2: this.state.noun2, + }; + + + + this.setState({ + adj1: '', + noun1: '', + adv: '', + verb: '', + adj2: '', + noun2: '', + count: this.state.count + 1 + }); + + this.props.onSubmissionCallback(newSubmission) + } render() { return (
-

Player Submission Form for Player #{ }

+

Player Submission Form for Player #{this.state.count}

-
+
+ + The - { - // Put your form inputs here... We've put in one below as an example - } + + + + the + + + ,
- +
From b4fb505201263ea36c7298862b312e4240b19cde Mon Sep 17 00:00:00 2001 From: Bitaman Date: Wed, 19 Jun 2019 21:35:01 -0700 Subject: [PATCH 2/2] added event handler to final poem --- src/components/FinalPoem.js | 37 +++++++++++++++++-------- src/components/Game.js | 34 +++++++++++++++++------ src/components/PlayerSubmissionForm.css | 2 ++ src/components/PlayerSubmissionForm.js | 37 ++++++++++++++++--------- src/components/RecentSubmission.js | 3 +- 5 files changed, 78 insertions(+), 35 deletions(-) diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js index d516184e..208a5561 100644 --- a/src/components/FinalPoem.js +++ b/src/components/FinalPoem.js @@ -3,18 +3,31 @@ import './FinalPoem.css'; const FinalPoem = (props) => { - return ( -
-
-

Final Poem

+ const poem = props.submissions.map((line, i) => { + return

{line}

+ }) + const handleClick = () => { + console.log("I am clicking") + props.poemCallback(); + } + const poemButton = +
+ +
-
+ const showpoem = +
+

Final Poem

+
{poem}
+
; + const content = props.isSubmitted? showpoem : poemButton -
- -
-
- ); -} + return ( +
+ {content} -export default FinalPoem; +
+ ); + } + + export default FinalPoem; diff --git a/src/components/Game.js b/src/components/Game.js index 2a4c1185..8d9da5fa 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -11,19 +11,32 @@ class Game extends Component { this.state = { submissions: [], isSubmitted: false, + counter: 1, } } - addSubmission = (newSubmission)=> { - console.log(newSubmission) + addSubmission = (newSentence)=> { + console.log(newSentence) let nextSubmission = this.state.submissions - nextSubmission.push(newSubmission) + nextSubmission.push(newSentence) this.setState({ - submissions: nextSubmission + submissions: nextSubmission, + counter: this.state.counter + 1 }) console.log(this.state.submissions) } + setSubmitted=()=> { + this.setState({ + isSubmitted: true, + counter: 1, + }) + } + + + + + render() { const exampleFormat = FIELDS.map((field) => { @@ -33,6 +46,9 @@ class Game extends Component { return field; } }).join(" "); + const playersubmissionform = this.state.isSubmitted? '' : + const recentsubmission = this.state.isSubmitted? '' : + return (
@@ -45,12 +61,12 @@ class Game extends Component {

{ exampleFormat }

+ {recentsubmission} + {playersubmissionform} + - - - - - + +
); diff --git a/src/components/PlayerSubmissionForm.css b/src/components/PlayerSubmissionForm.css index 7cded5d9..22dab04b 100644 --- a/src/components/PlayerSubmissionForm.css +++ b/src/components/PlayerSubmissionForm.css @@ -35,6 +35,8 @@ background-color: #FFE9E9; } + + .PlayerSubmissionForm__input--invalid::placeholder { color: black; } diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index 14efaa4b..e2cff9dc 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -12,14 +12,15 @@ class PlayerSubmissionForm extends Component { verb: '', adj2: '', noun2: '', - count: 0, } } + onInputChange = (event) => { const updatedState = {}; const field = event.target.name; const value = event.target.value; + updatedState[field] = value; this.setState(updatedState); @@ -27,14 +28,16 @@ class PlayerSubmissionForm extends Component { onFormSubmit = (event) => { event.preventDefault(); - const newSubmission = { - adj1: this.state.adj1, - noun1: this.state.noun1, - adv: this.state.adv, - verb: this.state.verb, - adj2: this.state.adj2, - noun2: this.state.noun2, - }; + // const newSubmission = { + // adj1: this.state.adj1, + // noun1: this.state.noun1, + // adv: this.state.adv, + // verb: this.state.verb, + // adj2: this.state.adj2, + // noun2: this.state.noun2, + // }; + const newSentence = "The " + this.state.adj1 + " " + this.state.noun1 + " " + this.state.adv + " " + this.state.verb + " the " + this.state.adj2 + " " + this.state.noun2 + console.log(newSentence) @@ -45,18 +48,20 @@ class PlayerSubmissionForm extends Component { verb: '', adj2: '', noun2: '', - count: this.state.count + 1 }); - this.props.onSubmissionCallback(newSubmission) + this.props.onSubmissionCallback(newSentence) } + + render() { - + // let classname = "PlayerSubmissionFormt__input--invalid" return (
-

Player Submission Form for Player #{this.state.count}

+ +

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

@@ -66,24 +71,28 @@ class PlayerSubmissionForm extends Component { the { + console.log(props) return (

The Most Recent Submission

-

{ }

+

{props.recentSubmission}

); }