diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 00000000..2cd8968b
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1 @@
+123,125
\ No newline at end of file
diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js
index d516184e..5bf4c939 100644
--- a/src/components/FinalPoem.js
+++ b/src/components/FinalPoem.js
@@ -1,18 +1,44 @@
-import React from 'react';
+import React, { useState } from 'react';
import './FinalPoem.css';
-const FinalPoem = (props) => {
+const FinalPoem = ({poem, onSubmitCallBack}) => {
+
+ // hooks/state organized here
+ const [showPoem, setShowPoem ] = useState('');
+ const [showFinalPoemButton, setShowFinalPoemButton] = useState(true);
+ let finalPoemLines = [];
+
+ poem.forEach (poemLine => {
+ finalPoemLines.push(Object.values(poemLine).join(" ").concat('.'));
+ });
+
+ const onFinalPoemButtonClick = (e) => {
+ // prevent default behavior
+ e.preventDefault();
+
+ let finalPoem = finalPoemLines.join('\n');
+ setShowPoem(finalPoem);
+ onSubmitCallBack(false);
+ setShowFinalPoemButton(false);
+ }
return (
}
);
}
diff --git a/src/components/Game.js b/src/components/Game.js
index ad27105b..a16a04fe 100644
--- a/src/components/Game.js
+++ b/src/components/Game.js
@@ -13,6 +13,31 @@ const Game = () => {
}
}).join(" ");
+ // Game.js keeps track of state
+ // all the hooks/useState organized here
+ const [poemLines, setPoemLines] = useState([]);
+ const [showRecentSubmission, setShowRecentSubmission] = useState(false);
+ const [showPlayerSubmissionForm, setShowPlayerSubmissionForm] = useState(true);
+
+ // use this example
+ // const addStudent = (student) => {
+ // Duplicate the student list.
+ // const newStudentList = [...students];
+ const addPoemLine = (poem) => {
+ const newPoemLines = [...poemLines];
+
+ newPoemLines.push(poem);
+
+ setPoemLines(newPoemLines);
+ setShowRecentSubmission(true);
+ }
+
+ const hidePlayerSubmissionForm = (value) => {
+ setShowPlayerSubmissionForm(value);
+ setShowRecentSubmission(false);
+ }
+
+
return (
Game
@@ -25,11 +50,12 @@ const Game = () => {
{ exampleFormat }
-
-
-
+ {/* figured out how to write the next two lines with && by looking at classmates' code */}
+ {showRecentSubmission &&
}
+ {/* define currentPlayerId here - got idea from Chris' video where he did student_id */}
+ {showPlayerSubmissionForm && }
-
+
);
@@ -66,4 +92,4 @@ const FIELDS = [
".",
];
-export default Game;
+export default Game;
\ No newline at end of file
diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js
index ba19e6ef..2575a737 100644
--- a/src/components/PlayerSubmissionForm.js
+++ b/src/components/PlayerSubmissionForm.js
@@ -1,22 +1,153 @@
import React, { useState } from 'react';
import './PlayerSubmissionForm.css';
-const PlayerSubmissionForm = () => {
+const PlayerSubmissionForm = ({onSubmitCallBack, currentPlayerId}) => {
+ // I did not do this project in the Waves as recommended. The instructions did not totally make sense to me.
+ // I got a solid 3 hours of tutoring while working on this project. React can get confusing - fast.
+ // I referenced this link often.
+ // https://codesandbox.io/s/serene-fire-no8p7?file=/src/components/SignupForm.js
+ const [formFields, setFormFields ] = useState({
+ the1: "The",
+ adj1: '',
+ noun1: '',
+ adv: '',
+ verb: '',
+ the2: 'the',
+ adj2: '',
+ noun2: ''
+ });
+
+ const inputs = {
+ // This feels repetitive - need to DRY
+ adj1: {
+ // This regex allows alphabetic characters only. However,
+ // upon the actual 'submit', non-alphabetic characters pass through my program! :(
+ validation: /[a-zA-Z]/,
+ },
+ noun1: {
+ validation: /[a-zA-Z]/,
+ },
+ adv: {
+ validation: /[a-zA-Z]/,
+ },
+ verb: {
+ validation: /[a-zA-Z]/,
+ },
+ adj2: {
+ validation: /[a-zA-Z]/,
+ },
+ noun2: {
+ validation: /[a-zA-Z]/,
+ }
+ };
+
+ const onInputChange = (event) => {
+ const newFormFields = {
+ // using the spread operator to grab ALL the form fields
+ ...formFields,
+ };
+
+ newFormFields[event.target.name] = event.target.value;
+ setFormFields(newFormFields);
+ };
+ // https://codesandbox.io/s/serene-fire-no8p7?file=/src/components/SignupForm.js
+ const validateField = fieldName => {
+ return inputs[fieldName].validation.test(formFields[fieldName]);
+ };
+
+ const onFormSubmit = (e) => {
+ // prevent default behavior which is to call external api (?)
+ e.preventDefault();
+
+ const formFieldsArray = Object.values(formFields);
+
+ // check if form fields are NOT empty
+ if (!formFieldsArray.includes('')) {
+
+ onSubmitCallBack(formFields);
+
+ setFormFields({
+ the1: "The",
+ adj1: '',
+ noun1: '',
+ adv: '',
+ verb: '',
+ the2: 'the',
+ adj2: '',
+ noun2: ''
+ });
+ }
+
+ }
+
return (
-
Player Submission Form for Player #{ }
+
Player Submission Form for Player #{currentPlayerId}
-