diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js index d516184e..81ab7fbb 100644 --- a/src/components/FinalPoem.js +++ b/src/components/FinalPoem.js @@ -1,20 +1,50 @@ import React from 'react'; import './FinalPoem.css'; +import PropTypes from "prop-types" const FinalPoem = (props) => { + const result = props.poems.map((poem, i) =>{ + const {firstAdjective, firstNoun, adverb, verb, secondAdjective, secondNoun} = poem; + return

The {firstAdjective} {firstNoun} {adverb} {verb} the {secondAdjective} {secondNoun} .

+ }) + + const onButtonClick = () =>{ + props.callBackOnShowPoem(); + }; + return (
-
+ {!props.showPoem &&

Final Poem

+ {result} -
+
} -
- -
+ {props.showPoem &&
+ +
}
); } +FinalPoem.propTypes = { + poems: PropTypes.arrayOf( + PropTypes.shape({ + firstAdjective: PropTypes.string.isRequired, + firstNoun: PropTypes.string.isRequired, + adverb: PropTypes.string.isRequired, + verb: PropTypes.string.isRequired, + secondAdjective: PropTypes.string.isRequired, + secondNoun: PropTypes.string.isRequired, + }) + ), + showPoem: PropTypes.bool.isRequired, + callBackOnShowPoem: PropTypes.func.isRequired, +}; + + export default FinalPoem; diff --git a/src/components/Game.js b/src/components/Game.js index ad27105b..1e19760b 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -5,6 +5,9 @@ import FinalPoem from './FinalPoem'; import RecentSubmission from './RecentSubmission'; const Game = () => { + const [poemSubmissions, setPoemList] = useState([]); + const [showPoem, setshowPoem] = useState(true); + const exampleFormat = FIELDS.map((field) => { if (field.key) { return field.placeholder; @@ -13,6 +16,25 @@ const Game = () => { } }).join(" "); + const callBackOnShowPoem = () => { + setshowPoem(false); + }; + + const addPoem = (poem) => { + const newPoemList = [...poemSubmissions]; + + newPoemList.push({ + firstAdjective: poem.firstAdjective, + firstNoun: poem.firstNoun, + adverb: poem.adverb, + verb: poem.verb, + secondAdjective: poem.secondAdjective, + secondNoun: poem.secondNoun, + }); + + setPoemList(newPoemList); + }; + return (

Game

@@ -24,12 +46,9 @@ const Game = () => {

{ exampleFormat }

- - - - - - + { (showPoem) && poemSubmissions.length > 0 && } + { (showPoem) && } +
); diff --git a/src/components/PlayerSubmissionForm.css b/src/components/PlayerSubmissionForm.css index 7cded5d9..22de80d6 100644 --- a/src/components/PlayerSubmissionForm.css +++ b/src/components/PlayerSubmissionForm.css @@ -35,6 +35,10 @@ background-color: #FFE9E9; } +input .valid{ + background-color: #FFFFFF; +} + .PlayerSubmissionForm__input--invalid::placeholder { color: black; } diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index ba19e6ef..3b5b65ff 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -1,22 +1,106 @@ import React, { useState } from 'react'; import './PlayerSubmissionForm.css'; +import PropTypes from "prop-types" + +const PlayerSubmissionForm = (props) => { + + const [count, setCurrenCount] = useState(1); + const [formFields, setFormFields] = useState({ + firstAdjective: '', + firstNoun: '', + adverb: '', + verb: '', + secondAdjective:'', + secondNoun: '', + }); + + const onInputChange = (event) => { + const newFormFields = { + ...formFields, + } + newFormFields[event.target.name] = event.target.value; + setFormFields(newFormFields); + }; + + const onSubmitForm = (event) => { + if (!inputValid()) return; + + event.preventDefault(); + + props.onCallBackPoem(formFields); + setCurrenCount(count + 1) + + setFormFields({ + firstAdjective: '', + firstNoun: '', + adverb: '', + verb: '', + secondAdjective:'', + secondNoun: '', + }); + }; + + const inputValid = () => { + return formFields.firstAdjective.match(/[a-zA-Z]/) + && formFields.firstNoun.match(/[a-zA-Z]/) + && formFields.adverb.match(/[a-zA-Z]/) + && formFields.verb.match(/[a-zA-Z]/) + && formFields.secondAdjective.match(/[a-zA-Z]/) + && formFields.secondNoun.match(/[a-zA-Z]/) + }; -const PlayerSubmissionForm = () => { return ( -
-

Player Submission Form for Player #{ }

+
+

Player Submission Form for Player #{count}

-
+
- - { - // Put your form inputs here... We've put in one below as an example - } + The - + + + + The + + + .
@@ -27,5 +111,9 @@ const PlayerSubmissionForm = () => { ); } +PlayerSubmissionForm.propTypes = { + onCallBackPoem: PropTypes.func.isRequired, +}; + export default PlayerSubmissionForm; diff --git a/src/components/RecentSubmission.js b/src/components/RecentSubmission.js index 663da34b..8747279b 100644 --- a/src/components/RecentSubmission.js +++ b/src/components/RecentSubmission.js @@ -1,13 +1,27 @@ import React from 'react'; import './RecentSubmission.css'; +import PropTypes from "prop-types" const RecentSubmission = (props) => { + + const {firstAdjective, firstNoun, adverb, verb, secondAdjective, secondNoun} = props.poem; return (

The Most Recent Submission

-

{ }

+

{`The ${firstAdjective} ${firstNoun} ${adverb} ${verb} the ${secondAdjective} ${secondNoun}`}

); } -export default RecentSubmission; +RecentSubmission.propTypes = { + poem: PropTypes.shape({ + firstAdjective: PropTypes.string.isRequired, + firstNoun: PropTypes.string.isRequired, + adverb: PropTypes.string.isRequired, + verb: PropTypes.string.isRequired, + secondAdjective: PropTypes.string.isRequired, + secondNoun: PropTypes.string.isRequired, + }) +}; + +export default RecentSubmission; \ No newline at end of file