diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js index d516184e..bccaf6b9 100644 --- a/src/components/FinalPoem.js +++ b/src/components/FinalPoem.js @@ -1,20 +1,39 @@ import React from 'react'; import './FinalPoem.css'; +import PropTypes from 'prop-types'; const FinalPoem = (props) => { + + const revealPoemButton = +
+ +
; + + + const poemContent = props.finalPlayerInput.map((line, i) => { + return

{ line }

; + }); - return ( -
+ const revealPoem =

Final Poem

+ {poemContent} +
; - + const content = props.isPoemSubmitted ? revealPoem : revealPoemButton -
- + return ( +
+ {content}
-
- ); + ); +} + +FinalPoem.propTypes = { + onPoemSubmittedCallback: PropTypes.isRequired, + isPoemSubmitted: PropTypes.isRequired, + finalPlayerInput: PropTypes.arrayOf(String), } export default FinalPoem; diff --git a/src/components/Game.js b/src/components/Game.js index e99f985a..924f9849 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -8,6 +8,32 @@ class Game extends Component { constructor(props) { super(props); + + this.state = { + playerInput: [], + isPoemSubmitted: false, + } + } + + + onPoemSubmittedCallback = () => { + this.setState({ + isPoemSubmitted: true, + }) + } + + + 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 + }) } render() { @@ -20,6 +46,12 @@ class Game extends Component { } }).join(" "); + const recentSubmission = + + const playerSubmissionForm = + return (

Game

@@ -31,19 +63,20 @@ class Game extends Component {

{ exampleFormat }

+ + {this.state.isPoemSubmitted ?
: recentSubmission} + {this.state.isPoemSubmitted ?
: playerSubmissionForm} - - - - - - +
); } } 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.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 1de05095..aa627c9c 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -1,29 +1,135 @@ import React, { Component } from 'react'; import './PlayerSubmissionForm.css'; +import PropTypes from 'prop-types'; class PlayerSubmissionForm extends Component { constructor(props) { super(props); + + this.state = { + + adj1: '', + noun1: '', + adv: '', + verb: '', + adj2: '', + noun2: '', + }; + + this.isValid = false + } + + 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); + this.isValid = true + + } + 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? + + const newSubmission = `The ${adj1} ${noun1} ${adv} ${verb} the ${adj2} ${noun2} .` + + this.props.addPlayerInputCallback(newSubmission); + this.resetState(); + } + + render() { + return (
-

Player Submission Form for Player #{ }

+

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

-
+ +
- - { - // Put your form inputs here... We've put in one below as an example - } - - +
The
+ + + + + +
the
+
@@ -35,4 +141,9 @@ class PlayerSubmissionForm extends Component { } } +PlayerSubmissionForm.propTypes = { + addPlayerInputCallback: PropTypes.isRequired, + playerNumber: PropTypes.number +} + export default PlayerSubmissionForm; diff --git a/src/components/RecentSubmission.js b/src/components/RecentSubmission.js index 663da34b..c0570346 100644 --- a/src/components/RecentSubmission.js +++ b/src/components/RecentSubmission.js @@ -1,13 +1,26 @@ import React from 'react'; import './RecentSubmission.css'; +import PropTypes from 'prop-types'; const RecentSubmission = (props) => { - return ( -
-

The Most Recent Submission

-

{ }

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

The Most Recent Submission

+

{props.latestSubmission}

+
+ ); + } else { + return ( +
+ ) + } +} + +RecentSubmission.propTypes = { + latestSubmission: PropTypes.string } export default RecentSubmission;