diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js
index d516184e..c7a65bdd 100644
--- a/src/components/FinalPoem.js
+++ b/src/components/FinalPoem.js
@@ -1,20 +1,48 @@
-import React from 'react';
-import './FinalPoem.css';
+import React from "react";
+import "./FinalPoem.css";
+import PropTypes from "prop-types";
-const FinalPoem = (props) => {
+const FinalPoem = props => {
+ let contents = "";
- return (
-
+ if (props.showFinalPoem) {
+ contents = (
-
+ );
+ } else {
+ contents = (
-
+
+ );
+ }
+
+ let finalPoem = "";
+ if (props.showFinalPoem) {
+ finalPoem = props.lines.map((line, i) => {
+ return
{line}
;
+ });
+ }
+
+ return (
+
+ {contents}
+ {finalPoem}
);
-}
+};
+
+FinalPoem.propTypes = {
+ showFinalPoem: PropTypes.bool.isRequired,
+ showFinalPoemCallback: PropTypes.func.isRequired,
+ lines: PropTypes.array.isRequired
+};
export default FinalPoem;
diff --git a/src/components/Game.js b/src/components/Game.js
index e99f985a..70471559 100644
--- a/src/components/Game.js
+++ b/src/components/Game.js
@@ -1,18 +1,36 @@
-import React, { Component } from 'react';
-import './Game.css';
-import PlayerSubmissionForm from './PlayerSubmissionForm';
-import FinalPoem from './FinalPoem';
-import RecentSubmission from './RecentSubmission';
+import React, { Component } from "react";
+import "./Game.css";
+import PlayerSubmissionForm from "./PlayerSubmissionForm";
+import FinalPoem from "./FinalPoem";
+import RecentSubmission from "./RecentSubmission";
class Game extends Component {
-
constructor(props) {
super(props);
+
+ this.state = {
+ lines: [],
+ finalPoem: false
+ };
}
- render() {
+ addLine = newLine => {
+ const lines = this.state.lines;
+ lines.push(newLine);
+
+ this.setState({
+ lines
+ });
+ };
- const exampleFormat = FIELDS.map((field) => {
+ revealPoem = () => {
+ this.setState({
+ finalPoem: true
+ });
+ };
+
+ render() {
+ const exampleFormat = FIELDS.map(field => {
if (field.key) {
return field.placeholder;
} else {
@@ -20,24 +38,53 @@ class Game extends Component {
}
}).join(" ");
+ let recentSub = "";
+
+ if (this.state.lines.length > 0) {
+ recentSub = (
+
+ );
+ }
+
+ let submissionForm = "";
+
+ if (!this.state.finalPoem) {
+ submissionForm = (
+
+ );
+ }
return (
Game
-
Each player should take turns filling out and submitting the form below. Each turn should be done individually and in secret! Take inspiration from the revealed recent submission. When all players are finished, click the final button on the bottom to reveal the entire poem.
-
-
Please follow the following format for your poetry submission:
-
-
- { exampleFormat }
+
+ Each player should take turns filling out and submitting the form
+ below. Each turn should be done individually and in secret! {" "}
+ Take inspiration from the revealed recent submission. When all players
+ are finished, click the final button on the bottom to reveal the
+ entire poem.
-
+
Please follow the following format for your poetry submission:
-
+
{exampleFormat}
-
+ {submissionForm}
+
);
}
@@ -46,31 +93,31 @@ class Game extends Component {
const FIELDS = [
"The",
{
- key: 'adj1',
- placeholder: 'adjective',
+ key: "adj1",
+ placeholder: "adjective"
},
{
- key: 'noun1',
- placeholder: 'noun',
+ key: "noun1",
+ placeholder: "noun"
},
{
- key: 'adv',
- placeholder: 'adverb',
+ key: "adv",
+ placeholder: "adverb"
},
{
- key: 'verb',
- placeholder: 'verb',
+ key: "verb",
+ placeholder: "verb"
},
"the",
{
- key: 'adj2',
- placeholder: 'adjective',
+ key: "adj2",
+ placeholder: "adjective"
},
{
- key: 'noun2',
- placeholder: 'noun',
+ key: "noun2",
+ placeholder: "noun"
},
- ".",
+ "."
];
export default Game;
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..e319e4c4 100644
--- a/src/components/PlayerSubmissionForm.js
+++ b/src/components/PlayerSubmissionForm.js
@@ -1,33 +1,162 @@
-import React, { Component } from 'react';
-import './PlayerSubmissionForm.css';
+import React, { Component } from "react";
+import "./PlayerSubmissionForm.css";
+import PropTypes from "prop-types";
class PlayerSubmissionForm extends Component {
-
constructor(props) {
super(props);
+
+ const userInput = {};
+
+ props.fields.forEach(field => {
+ if (field.key) {
+ userInput[field.key] = "";
+ }
+ });
+
+ this.state = userInput;
}
- render() {
+ onFieldChange = event => {
+ const { name, value } = event.target;
+
+ const updatedState = {};
+ updatedState[name] = value;
+
+ this.setState(updatedState);
+ };
+
+ validString = value => {
+ return value !== "";
+ };
+
+ onFormSubmit = event => {
+ event.preventDefault();
+
+ let allValid = true;
+
+ Object.values(this.state).forEach(value => {
+ if (!this.validString(value)) {
+ allValid = false;
+ }
+ });
+
+ if (!allValid) {
+ return;
+ }
+
+ let newPoemLine = [];
+
+ this.props.fields.forEach(field => {
+ if (field.key) {
+ newPoemLine.push(this.state[field.key]);
+ } else {
+ newPoemLine.push(field);
+ }
+ });
+
+ newPoemLine = newPoemLine.join(" ");
+ const resetState = {};
+
+ this.props.fields.forEach(field => {
+ if (field.key) {
+ resetState[field.key] = "";
+ }
+ });
+
+ this.setState(resetState);
+
+ this.props.addPoemLineCallback(newPoemLine);
+ };
+
+ render() {
return (
-
Player Submission Form for Player #{ }
-
-
@@ -35,4 +164,10 @@ class PlayerSubmissionForm extends Component {
}
}
+PlayerSubmissionForm.propTypes = {
+ addPoemLineCallback: PropTypes.func.isRequired,
+ fields: PropTypes.array.isRequired,
+ playerNum: PropTypes.number.isRequired
+};
+
export default PlayerSubmissionForm;
diff --git a/src/components/RecentSubmission.js b/src/components/RecentSubmission.js
index 663da34b..34e301eb 100644
--- a/src/components/RecentSubmission.js
+++ b/src/components/RecentSubmission.js
@@ -1,13 +1,18 @@
-import React from 'react';
-import './RecentSubmission.css';
+import React from "react";
+import "./RecentSubmission.css";
+import PropTypes from "prop-types";
-const RecentSubmission = (props) => {
+const RecentSubmission = props => {
return (
The Most Recent Submission
-
{ }
+
{props.recentSub}
);
-}
+};
+
+RecentSubmission.propTypes = {
+ recentSub: PropTypes.string.isRequired
+};
export default RecentSubmission;