diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js index d516184e..29db47cd 100644 --- a/src/components/FinalPoem.js +++ b/src/components/FinalPoem.js @@ -2,17 +2,29 @@ import React from 'react'; import './FinalPoem.css'; const FinalPoem = (props) => { + const showPoemButton = +
+ +
+ const allVerses = props.poem.map((verse, i) => { + return

{verse}

+ }); - return ( -
-
-

Final Poem

- + const finalPoem = +
+

Final Poem

+ {allVerses}
- -
- -
+ + const displayFinalPoem = props.showPoem ? finalPoem : showPoemButton; + + return ( +
+ { displayFinalPoem }
); } diff --git a/src/components/Game.js b/src/components/Game.js index e99f985a..6f79bd95 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -8,11 +8,33 @@ class Game extends Component { constructor(props) { super(props); + + this.state = { + poem: [], + showPoem: false, + }; } + + // Changes state and adds the new verse to the peom array. + addSubmission = (verse) => { + let newVerse = this.state.poem; + + newVerse.push(verse); + this.setState({ + poem: newVerse, + }); + } + + showFinalPoem = (event) => { + event.preventDefault(); + this.setState({ + showPoem: true + }) + } render() { - const exampleFormat = FIELDS.map((field) => { + const exampleFormat = SUBMISSIONS.map((field) => { if (field.key) { return field.placeholder; } else { @@ -32,18 +54,24 @@ class Game extends Component { { exampleFormat }

- + - + - +
); } } -const FIELDS = [ +const SUBMISSIONS = [ "The", { key: 'adj1', diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index 1de05095..c0ed3b4b 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -5,25 +5,122 @@ class PlayerSubmissionForm extends Component { constructor(props) { super(props); + + this.state = { + adj1: '', + noun1: '', + adv: '', + verb: '', + adj2: '', + noun2: '', + }; + } + // all fields need at least one character + validations = { + adj1: /.+/, + noun1: /.+/, + adv: /.+/, + verb: /.+/, + adj2: /.+/, + noun2: /.+/, + } + + fieldValid = (fieldName) => { + return this.validations[fieldName].test(this.state[fieldName]); + } + + onChangeHandler = (event) => { + + const field = {} + field[event.target.name] = event.target.value + this.setState(field) } + + handleSubmit = (event) => { + event.preventDefault(); + let allFieldsValid = true; + + Object.keys(this.validations).forEach((fieldName) => { + if (!this.fieldValid(fieldName)) { + allFieldsValid = false; + } + }) + + if (allFieldsValid) { + this.props.addSubmissionCallback({ + adj1: this.state.adj1, + noun1: this.state.noun1, + adv: this.state.adverb, + verb: this.state.verb, + adj2: this.state.adj2, + noun2: this.state.noun2, + }) + this.setState({ + adj1: '', + noun1: '', + adv: '', + verb: '', + adj2: '', + noun2: '', + }) + } + } render() { return (
-

Player Submission Form for Player #{ }

+

Player Submission Form for Player #{ this.props.player + 1 }

-
+
+

The

+ - { - // Put your form inputs here... We've put in one below as an example - } + + + + + +

the

+ + + + +

.

diff --git a/src/components/RecentSubmission.js b/src/components/RecentSubmission.js index 663da34b..419933b4 100644 --- a/src/components/RecentSubmission.js +++ b/src/components/RecentSubmission.js @@ -2,12 +2,16 @@ import React from 'react'; import './RecentSubmission.css'; const RecentSubmission = (props) => { + if (props.lastVerse) { return (

The Most Recent Submission

-

{ }

+

The {props.lastVerse.adj1} {props.lastVerse.noun1} {props.lastVerse.adv} {props.lastVerse.verb} the {props.lastVerse.adj2} {props.lastVerse.noun2}.

); +} else { + return null +} } export default RecentSubmission;