From 766e41e2724acd0c01ab74c64b530733fd0f20a9 Mon Sep 17 00:00:00 2001 From: Katie Date: Wed, 22 Apr 2020 21:37:48 -0700 Subject: [PATCH 1/4] completed wave 1 --- src/components/Game.js | 16 ++++- src/components/PlayerSubmissionForm.js | 94 ++++++++++++++++++++++++-- 2 files changed, 105 insertions(+), 5 deletions(-) diff --git a/src/components/Game.js b/src/components/Game.js index ad27105b..6a8b127f 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -4,6 +4,8 @@ import PlayerSubmissionForm from './PlayerSubmissionForm'; import FinalPoem from './FinalPoem'; import RecentSubmission from './RecentSubmission'; +const submissionsList = [] + const Game = () => { const exampleFormat = FIELDS.map((field) => { if (field.key) { @@ -13,6 +15,18 @@ const Game = () => { } }).join(" "); + const addSubmission = (newSubmission) => { + const newSubmissionList = [...submissionsList]; + + newSubmissionList.push(newSubmission) + console.log("the new submission (in game)") + console.log(newSubmission) + console.log("the new submission list (in game)") + console.log(newSubmissionList) + } + + + return (

Game

@@ -27,7 +41,7 @@ const Game = () => { - + diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index ba19e6ef..dd2d218d 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -1,21 +1,107 @@ import React, { useState } from 'react'; import './PlayerSubmissionForm.css'; -const PlayerSubmissionForm = () => { + +const PlayerSubmissionForm = (props) => { + + const [submission, setSubmission] = useState({ + adj1: '', + noun1: '', + adv: '', + verb: '', + adj2: '', + noun2: '', + }); + + const onFormSubmit = (event) => { + event.preventDefault(); + + console.log(event.target) + + props.onSubmitCallback(submission) + + setSubmission({ + adj1: '', + noun1: '', + adv: '', + verb: '', + adj2: '', + noun2: '', + }) + + }; + + const onInputChange = (event) => { + console.log(`Changing field ${ event.target.name } to ${ event.target.value }`); + // Duplicate formFields into new object + const newSubmissionFields = { + ...submission, + } + + newSubmissionFields[event.target.name] = event.target.value; + setSubmission(newSubmissionFields); + } + return (

Player Submission Form for Player #{ }

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

{props.fields[0]}

+ + placeholder={props.fields[1].placeholder} + value={submission.adj1} + name="adj1" + type="text" + onChange={onInputChange}/> + + + + + + + +

{props.fields[5]}

+ + + +
From 0860f62c8736f00740127791ac3481aa2ab415fc Mon Sep 17 00:00:00 2001 From: Katie Date: Wed, 22 Apr 2020 21:47:17 -0700 Subject: [PATCH 2/4] finished implementing user stories of wave 1 --- src/components/Game.js | 13 +++++++------ src/components/PlayerSubmissionForm.js | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/Game.js b/src/components/Game.js index 6a8b127f..3736628c 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -15,14 +15,15 @@ const Game = () => { } }).join(" "); + const [submissions, setSubmissionList] = useState(submissionsList) + const addSubmission = (newSubmission) => { - const newSubmissionList = [...submissionsList]; + + const newSubmissionList = [...submissions]; newSubmissionList.push(newSubmission) - console.log("the new submission (in game)") - console.log(newSubmission) - console.log("the new submission list (in game)") - console.log(newSubmissionList) + setSubmissionList(newSubmissionList) + } @@ -41,7 +42,7 @@ const Game = () => { - + diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index dd2d218d..fd1a14b8 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -44,7 +44,7 @@ const PlayerSubmissionForm = (props) => { return (
-

Player Submission Form for Player #{ }

+

Player Submission Form for Player #{props.playerNumber}

Date: Wed, 22 Apr 2020 22:54:45 -0700 Subject: [PATCH 3/4] implemented wave 2 --- src/components/FinalPoem.js | 13 +++++++++++-- src/components/Game.js | 27 ++++++++++++++++++++++----- src/components/RecentSubmission.js | 3 ++- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js index d516184e..ed5deb47 100644 --- a/src/components/FinalPoem.js +++ b/src/components/FinalPoem.js @@ -1,13 +1,22 @@ -import React from 'react'; +import React, {useState} from 'react'; import './FinalPoem.css'; + const FinalPoem = (props) => { + const listOfSentences = props.submissions.map(submission => { + return ( +

The {submission.adj1} {submission.noun1} {submission.adv} {submission.verb} the {submission.ajd2} {submission.noun2}.

+ ); + }) + + + return (

Final Poem

- + {listOfSentences}
diff --git a/src/components/Game.js b/src/components/Game.js index 3736628c..1a250982 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -4,7 +4,6 @@ import PlayerSubmissionForm from './PlayerSubmissionForm'; import FinalPoem from './FinalPoem'; import RecentSubmission from './RecentSubmission'; -const submissionsList = [] const Game = () => { const exampleFormat = FIELDS.map((field) => { @@ -15,7 +14,7 @@ const Game = () => { } }).join(" "); - const [submissions, setSubmissionList] = useState(submissionsList) + const [submissions, setSubmissionList] = useState([]) const addSubmission = (newSubmission) => { @@ -23,7 +22,15 @@ const Game = () => { newSubmissionList.push(newSubmission) setSubmissionList(newSubmissionList) + console.log(newSubmissionList) + }; + + let mostRecentSubmissionSentence = "" + + if (submissions.length > 0){ + let mostRecentSubmission = submissions[submissions.length-1] + mostRecentSubmissionSentence = "The " + mostRecentSubmission.adj1 + " " + mostRecentSubmission.noun1 + " " + mostRecentSubmission.adv + " " + mostRecentSubmission.verb + " the " + mostRecentSubmission.adj2 + " " + mostRecentSubmission.noun2 + "." } @@ -40,11 +47,21 @@ const Game = () => { { exampleFormat }

- + + - + - +
); diff --git a/src/components/RecentSubmission.js b/src/components/RecentSubmission.js index 663da34b..a34c1fe2 100644 --- a/src/components/RecentSubmission.js +++ b/src/components/RecentSubmission.js @@ -2,10 +2,11 @@ import React from 'react'; import './RecentSubmission.css'; const RecentSubmission = (props) => { + return (

The Most Recent Submission

-

{ }

+

{props.mostRecentSubmission}

); } From 62f076bd65ebc65ad2a3742f76833986e4e719f9 Mon Sep 17 00:00:00 2001 From: Katie Date: Wed, 22 Apr 2020 23:48:34 -0700 Subject: [PATCH 4/4] implemented wave 3 --- src/components/FinalPoem.js | 13 +++++++++++-- src/components/Game.js | 11 ++++++----- src/components/PlayerSubmissionForm.js | 25 ++++++++++++++----------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js index ed5deb47..672950ad 100644 --- a/src/components/FinalPoem.js +++ b/src/components/FinalPoem.js @@ -4,23 +4,32 @@ import './FinalPoem.css'; const FinalPoem = (props) => { + const emptyList =

const listOfSentences = props.submissions.map(submission => { return (

The {submission.adj1} {submission.noun1} {submission.adv} {submission.verb} the {submission.ajd2} {submission.noun2}.

); }) + const [reveal, setReveal] = useState(false) + + const revealSentences = () => { + props.setGameOverCallback(true); + setReveal(true); + } + + return (

Final Poem

- {listOfSentences} + {reveal ? listOfSentences : emptyList}
- + {reveal ? "" : }
); diff --git a/src/components/Game.js b/src/components/Game.js index 1a250982..04bd4fad 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -33,7 +33,7 @@ const Game = () => { mostRecentSubmissionSentence = "The " + mostRecentSubmission.adj1 + " " + mostRecentSubmission.noun1 + " " + mostRecentSubmission.adv + " " + mostRecentSubmission.verb + " the " + mostRecentSubmission.adj2 + " " + mostRecentSubmission.noun2 + "." } - + const [gameOver, setGameOver] = useState(false) return (
@@ -47,20 +47,21 @@ const Game = () => { { exampleFormat }

- + />} - + />}
diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index fd1a14b8..cf6eb870 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -33,7 +33,7 @@ const PlayerSubmissionForm = (props) => { const onInputChange = (event) => { console.log(`Changing field ${ event.target.name } to ${ event.target.value }`); - // Duplicate formFields into new object + const newSubmissionFields = { ...submission, } @@ -53,10 +53,6 @@ const PlayerSubmissionForm = (props) => {
- { - // Put your form inputs here... We've put in one below as an example - } -

{props.fields[0]}

{ value={submission.adj1} name="adj1" type="text" - onChange={onInputChange}/> + onChange={onInputChange} + className={ submission.adj1 !== "" ? "valid" : "PlayerSubmissionFormt__input--invalid"} + /> + onChange={onInputChange} + className={ submission.noun1 !== "" ? "valid" : "PlayerSubmissionFormt__input--invalid"}/> + onChange={onInputChange} + className={ submission.adv !== "" ? "valid" : "PlayerSubmissionFormt__input--invalid"}/> + onChange={onInputChange} + className={ submission.verb !== "" ? "valid" : "PlayerSubmissionFormt__input--invalid"}/>

{props.fields[5]}

@@ -94,14 +95,16 @@ const PlayerSubmissionForm = (props) => { value={submission.adj2} name="adj2" type="text" - onChange={onInputChange}/> + onChange={onInputChange} + className={ submission.adj2 !== "" ? "valid" : "PlayerSubmissionFormt__input--invalid"}/> + onChange={onInputChange} + className={ submission.noun2 !== "" ? "valid" : "PlayerSubmissionFormt__input--invalid"}/>