Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/components/FinalPoem.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
import React from 'react';
import './FinalPoem.css';
import PropTypes from 'prop-types';

const FinalPoem = (props) => {
const sentences = props.sentences.map((sentence, i) => {
return (
<p key={i}> { sentence } </p>
);
})

return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>

</section>

{
props.completedGame &&
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
{ sentences }
</section>
}
<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
{
!props.completedGame &&
<input onClick={props.onPoemComplete} type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
}
</div>
</div>
);
}

FinalPoem.propTypes = {
sentences: PropTypes.arrayOf(PropTypes.string).isRequired,
completedGame: PropTypes.bool.isRequired,
onPoemComplete: PropTypes.func.isRequired
}
export default FinalPoem;


30 changes: 27 additions & 3 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ class Game extends Component {

constructor(props) {
super(props);

this.state = {
sentences: [],
completed: false
}
}

onPlayerSubmit = (submissionData) => {
this.setState({
sentences: this.state.sentences.concat(submissionData)
})

}

completePoem = () => {
this.setState({
completed: true
})
}

render() {
Expand All @@ -20,6 +38,8 @@ class Game extends Component {
}
}).join(" ");

const lastIndex= this.state.sentences.length - 1

return (
<div className="Game">
<h2>Game</h2>
Expand All @@ -32,11 +52,15 @@ class Game extends Component {
{ exampleFormat }
</p>

<RecentSubmission />
<RecentSubmission recentSubmission={this.state.sentences[lastIndex]} />
{
!this.state.completed &&
<PlayerSubmissionForm onFormSubmit={this.onPlayerSubmit}/>
}

<PlayerSubmissionForm />


<FinalPoem />
<FinalPoem sentences={this.state.sentences} completedGame={this.state.completed} onPoemComplete={this.completePoem}/>

</div>
);
Expand Down
89 changes: 82 additions & 7 deletions src/components/PlayerSubmissionForm.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,99 @@
import React, { Component } from 'react';
import './PlayerSubmissionForm.css';
import PropTypes from 'prop-types';

class PlayerSubmissionForm extends Component {

constructor(props) {
super(props);
this.state = {
words: ["", "", "", "", "", ""],
count: 1
}
}

onInputChange = (event) => {
const name = event.target.name
const value = event.target.value

const index = parseInt(name, 10);
let oldWords = this.state.words;
oldWords[index] = value

this.setState({
words: oldWords
})
}

clickedPlayerSubmission = (event) => {
event.preventDefault()
const sentence = this.state.words.join(" ")
this.props.onFormSubmit(sentence)
this.setState({
words: ["", "", "", "", "", ""],
count: this.state.count + 1
})
}


render() {

return (
<div className="PlayerSubmissionForm">
<h3>Player Submission Form for Player #{ }</h3>
<h3>Player Submission Form for Player #{this.state.count }</h3>

<form className="PlayerSubmissionForm__form" >
<form onSubmit={this.clickedPlayerSubmission} className="PlayerSubmissionForm__form" >

<div className="PlayerSubmissionForm__poem-inputs">
The
<input
className={this.state.words[0].length > 0 ? "": "PlayerSubmissionFormt__input--invalid"}
value={this.state.words[0]}
placeholder="Adjective"
type="text"
onChange={this.onInputChange}
name="0" />

<input
className={this.state.words[1].length > 0 ? "": "PlayerSubmissionFormt__input--invalid"}
value={this.state.words[1]}
placeholder="Noun"
type="text"
onChange={this.onInputChange}
name="1" />

{
// Put your form inputs here... We've put in one below as an example
}
<input
placeholder="hm..."
type="text" />
className={this.state.words[2].length > 0 ? "": "PlayerSubmissionFormt__input--invalid"}
value={this.state.words[2]}
placeholder="Adverb"
type="text"
onChange={this.onInputChange}
name="2" />

<input
className={this.state.words[3].length > 0 ? "": "PlayerSubmissionFormt__input--invalid"}
value={this.state.words[3]}
placeholder="Verb"
type="text"
onChange={this.onInputChange}
name="3" />

the
<input
className={this.state.words[4].length > 0 ? "": "PlayerSubmissionFormt__input--invalid"}
value={this.state.words[4]}
placeholder="Adjective"
type="text"
onChange={this.onInputChange}
name="4" />

<input
className={this.state.words[5].length > 0 ? "": "PlayerSubmissionFormt__input--invalid"}
value={this.state.words[5]}
placeholder="Noun"
type="text"
onChange={this.onInputChange}
name="5" />.

</div>

Expand All @@ -35,4 +106,8 @@ class PlayerSubmissionForm extends Component {
}
}

PlayerSubmissionForm.propTypes = {
onFormSubmit: PropTypes.func.isRequired,
}

export default PlayerSubmissionForm;
20 changes: 14 additions & 6 deletions src/components/RecentSubmission.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import React from 'react';
import './RecentSubmission.css';
import PropTypes from 'prop-types';

const RecentSubmission = (props) => {
return (
<div className="RecentSubmission">
<h3>The Most Recent Submission</h3>
<p className="RecentSubmission__submission">{ }</p>
</div>
);
if (props.recentSubmission === undefined){
return null
} else {
return (
<div className="RecentSubmission">
<h3>The Most Recent Submission</h3>
<p className="RecentSubmission__submission">{ props.recentSubmission }</p>
</div>
);
}
}

RecentSubmission.propTypes = {
recentSubmission: PropTypes.string
}
export default RecentSubmission;