diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js
index d516184e..a6e7fa75 100644
--- a/src/components/FinalPoem.js
+++ b/src/components/FinalPoem.js
@@ -5,14 +5,18 @@ const FinalPoem = (props) => {
return (
+ {props.showPoem ? (
Final Poem
-
+ {props.poem.map((poemLine, i) => (
+ {poemLine}
+ ))}
-
-
);
}
diff --git a/src/components/Game.js b/src/components/Game.js
index e99f985a..2b05407f 100644
--- a/src/components/Game.js
+++ b/src/components/Game.js
@@ -4,14 +4,68 @@ import PlayerSubmissionForm from './PlayerSubmissionForm';
import FinalPoem from './FinalPoem';
import RecentSubmission from './RecentSubmission';
+const FIELDS = [
+ "The",
+ {
+ key: 'adj1',
+ placeholder: 'adjective',
+ name: 'adjectiveFirst',
+ },
+ {
+ key: 'noun1',
+ placeholder: 'noun',
+ name: 'nounFirst'
+ },
+ {
+ key: 'adv',
+ placeholder: 'adverb',
+ name: 'adverb'
+ },
+ {
+ key: 'verb',
+ placeholder: 'verb',
+ name: 'verb'
+ },
+ "the",
+ {
+ key: 'adj2',
+ placeholder: 'adjective',
+ name: 'adjectiveSecond'
+ },
+ {
+ key: 'noun2',
+ placeholder: 'noun',
+ name: 'nounSecond'
+ },
+ ".",
+];
+
class Game extends Component {
constructor(props) {
super(props);
+ this.state = {
+ poem: [],
+ showPoem: false
+ };
}
- render() {
-
+ addLineToPoem = (poemLine) => {
+ this.setState((prevState) => ({
+ poem: [
+ ...prevState.poem,
+ poemLine
+ ]
+ }));
+ }
+ // ... is saying: in this spot on the code, take all the elements on the array and add them one by one
+ // prevState(variable name) will always give you the most current version of state
+ handleDisplayPoem = () => {
+ this.setState({ showPoem: true });
+ }
+
+ render() {
+ console.log(this.state.poem)
const exampleFormat = FIELDS.map((field) => {
if (field.key) {
return field.placeholder;
@@ -32,45 +86,23 @@ class Game extends Component {
{ exampleFormat }
-
+ {!this.state.showPoem && (
+ <>
-
-
-
+
+
+
+ >
+ )}
+
);
}
}
-const FIELDS = [
- "The",
- {
- key: 'adj1',
- placeholder: 'adjective',
- },
- {
- key: 'noun1',
- placeholder: 'noun',
- },
- {
- key: 'adv',
- placeholder: 'adverb',
- },
- {
- key: 'verb',
- placeholder: 'verb',
- },
- "the",
- {
- key: 'adj2',
- placeholder: 'adjective',
- },
- {
- key: 'noun2',
- placeholder: 'noun',
- },
- ".",
-];
-
export default Game;
diff --git a/src/components/PlayerSubmissionForm.css b/src/components/PlayerSubmissionForm.css
index 7cded5d9..fce16195 100644
--- a/src/components/PlayerSubmissionForm.css
+++ b/src/components/PlayerSubmissionForm.css
@@ -31,10 +31,14 @@
background-color: tomato;
}
-.PlayerSubmissionFormt__input--invalid {
+.PlayerSubmissionForm__input--invalid {
background-color: #FFE9E9;
}
.PlayerSubmissionForm__input--invalid::placeholder {
color: black;
}
+
+.red {
+ background-color: red
+}
\ No newline at end of file
diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js
index 1de05095..edf92838 100644
--- a/src/components/PlayerSubmissionForm.js
+++ b/src/components/PlayerSubmissionForm.js
@@ -4,14 +4,55 @@ import './PlayerSubmissionForm.css';
class PlayerSubmissionForm extends Component {
constructor(props) {
- super(props);
- }
+ super(props); super(props);
+ this.state = {
+ adjectiveFirst: '',
+ nounFirst: '',
+ adverb: '',
+ verb: '',
+ adjectiveSecond: '',
+ nounSecond: ''
+ };
+ }
+
+ handleChange = (event) => {
+ const newState = {};
+ newState[event.target.name] = event.target.value;
+ this.setState(newState);
+ console.log(this.state);
+ };
+
+ handleClick = (event) => {
+ event.preventDefault();
+ const sentence = this.props.fields.reduce((acc, field, i) => {
+ if (field.key) {
+ return `${acc} ${this.state[field.name].trim()}`;
+ }
+ else {
+ if (i > 0 && i < (this.props.fields.length - 1)) {
+ return `${acc} ${field}`;
+ }
+ return `${acc}${field}`;
+ }
+ }, '');
+
+ this.props.onSubmitLine(sentence);
+
+ this.setState({
+ adjectiveFirst: '',
+ nounFirst: '',
+ adverb: '',
+ verb: '',
+ adjectiveSecond: '',
+ nounSecond: ''
+ });
+ };
render() {
return (