diff --git a/package-lock.json b/package-lock.json index ed444293..1b936036 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7888,6 +7888,11 @@ "resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz", "integrity": "sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=" }, + "lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=" + }, "lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", @@ -8543,6 +8548,15 @@ "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==" }, + "object-set-all-values-to": { + "version": "3.9.25", + "resolved": "https://registry.npmjs.org/object-set-all-values-to/-/object-set-all-values-to-3.9.25.tgz", + "integrity": "sha512-IV0HwwHzrMBszqxXlmpa5I5xu0SKFhctPNrtZfMvWLjd/Yb2msGaPKNFk1MBD3uweJ4Hy332BzpissBN3t0VHA==", + "requires": { + "lodash.clonedeep": "^4.5.0", + "type-detect": "^4.0.8" + } + }, "object-visit": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/object-visit/-/object-visit-1.0.1.tgz", @@ -11915,6 +11929,11 @@ "prelude-ls": "~1.1.2" } }, + "type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==" + }, "type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", diff --git a/package.json b/package.json index 82c6fc64..f5253781 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { + "object-set-all-values-to": "^3.9.25", "react": "^16.6.3", "react-dom": "^16.6.3", "react-scripts": "3.0.1" diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js index d516184e..e92024ef 100644 --- a/src/components/FinalPoem.js +++ b/src/components/FinalPoem.js @@ -1,17 +1,34 @@ import React from 'react'; import './FinalPoem.css'; + + const FinalPoem = (props) => { + + const onClickFinalPoem = () =>{ + + props.onFinalPoemButtonCallback(); + + } + + console.log(props.poem) + + const lines = function () { + if (props.clicked){ + return props.poem.map((poem, index) =>

{poem}

) + } + } + return (

Final Poem

- + {lines()}
- +
); diff --git a/src/components/Game.js b/src/components/Game.js index e99f985a..1a48502f 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -4,10 +4,88 @@ import PlayerSubmissionForm from './PlayerSubmissionForm'; import FinalPoem from './FinalPoem'; import RecentSubmission from './RecentSubmission'; + class Game extends Component { constructor(props) { super(props); + this.state = INITIAL_STATE; + } + + renderRecentSubmission() { + if(this.state.mostRencentSubmission !== '' && this.state.finalPoemClicked === false) { + return ( + + ) + } + } + + renderPlayerSubmissionForm(){ + if(this.state.finalPoemClicked === false){ + return ( + + ) + } + } + + renderFinalPoem(){ + + console.log(this.state.finalPoem) + return( + + ) + } + + onPlayerFormButton = (event, submission) => { + + event.preventDefault(); + + let last = '' + + Object.keys(submission).map(function(key){ + + if(key === 'adj1'){ + last += 'The ' + } else if (key === 'adj2') { + last += 'the' + } + return (last += submission[key] + ' ') + + }) + + const newFinalPoem = [ + ...this.state.finalPoem, + last + ]; + this.setState({ + finalPoem: newFinalPoem, + mostRencentSubmission: last, + }) + + this.renderPlayerSubmissionForm() + + } + + onFinalPoemButton = () => { + + console.log(this.state.finalPoem) + + let clicked; + let value = '' + + + if (this.state.finalPoemClicked === false) { + + clicked = true + value = "Play again!" + + } + + this.setState(!clicked ? INITIAL_STATE : { + finalPoemClicked: clicked, + finalPoemButtonValue: value, + }) + } render() { @@ -32,17 +110,25 @@ class Game extends Component { { exampleFormat }

- + {this.renderRecentSubmission()} - + {this.renderPlayerSubmissionForm()} - + {this.renderFinalPoem()} ); } } +const INITIAL_STATE = { + mostRencentSubmission: '', + finalPoem: [], + poem: '', + finalPoemClicked: false, + finalPoemButtonValue: "We are finished: Reveal the Poem", +}; + const FIELDS = [ "The", { diff --git a/src/components/PlayerSubmissionForm.css b/src/components/PlayerSubmissionForm.css index 7cded5d9..6d6f98eb 100644 --- a/src/components/PlayerSubmissionForm.css +++ b/src/components/PlayerSubmissionForm.css @@ -31,7 +31,7 @@ background-color: tomato; } -.PlayerSubmissionFormt__input--invalid { +.PlayerSubmissionForm__input--invalid { background-color: #FFE9E9; } diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index 1de05095..862ca69f 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -1,33 +1,97 @@ import React, { Component } from 'react'; import './PlayerSubmissionForm.css'; +import setAllValuesTo from "object-set-all-values-to"; class PlayerSubmissionForm extends Component { - + constructor(props) { super(props); + this.state = { + submission: { + adj1: '', + noun1: '', + adv: '', + verb: '', + adj2: '', noun2: '' + }, + fullSubmission: '', + name: '', + turn: 1, + inputClassName: '--invalid' + } } + onChangeInput = (event) => { + + event.target.className = "PlayerSubmissionForm__input"; + + let submission = { + ...this.state.submission, + [event.target.name]: event.target.value + }; + + this.setState({ + submission + }); + + console.log(submission) + + } + + onSubmitForm = (event) => { + event.preventDefault(); + const{ + submission, + turn + } = this.state; + this.props.onPlayerFormButtonCallback(event, submission); + let newSub = setAllValuesTo(submission, ''); + console.log(newSub === submission); + this.setState({ + submission: setAllValuesTo(submission, '') , + fullSubmission: '', + turn: turn + 1, + }) + } + + + render() { + let formFields = this.props.fields.map(field => { + if (typeof field === "string") { + return field; + } else { + const { + key, + placeholder + } = field; + return ( + + ); + } + + }) + return (
-

Player Submission Form for Player #{ }

+

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

- - { - // Put your form inputs here... We've put in one below as an example - } - - + { formFields }
- +
diff --git a/src/components/RecentSubmission.js b/src/components/RecentSubmission.js index 663da34b..f428a9fd 100644 --- a/src/components/RecentSubmission.js +++ b/src/components/RecentSubmission.js @@ -5,7 +5,7 @@ const RecentSubmission = (props) => { return (

The Most Recent Submission

-

{ }

+

{ props.mostRecentSubmission }

); }