Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ports - Laneia #36

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
8 changes: 6 additions & 2 deletions src/components/FinalPoem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ import './FinalPoem.css';

const FinalPoem = (props) => {

const formattedPoem = props.poem.map((line, i) => {
return <p key={i}>{line}</p>
})

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

{props.displayPoem && formattedPoem}
</section>

<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
{!props.displayPoem && <input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" onClick = {props.revealPoem}/>}
</div>
</div>
);
Expand Down
35 changes: 31 additions & 4 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ class Game extends Component {

constructor(props) {
super(props);

this.state = {
poem: []
}
}

addLine = (poemLine) => {
let poem = [...this.state.poem];

poem.push(poemLine)
this.setState({
poem: poem
});
}

revealPoem = () => {
this.setState({
displayPoem: true
});
}

render() {
Expand All @@ -32,11 +51,19 @@ class Game extends Component {
{ exampleFormat }
</p>

<RecentSubmission />

<PlayerSubmissionForm />
{ !this.state.displayPoem &&
<RecentSubmission line={[...this.state.poem].pop()}/>
}

<FinalPoem />
{ !this.state.displayPoem &&
<PlayerSubmissionForm
addLine = {(poemLine) => this.addLine(poemLine)}
submissionNumber = {this.state.poem.length + 1}/>
}

<FinalPoem displayPoem={this.state.displayPoem}
revealPoem={this.revealPoem}
poem={this.state.poem}/>

</div>
);
Expand Down
88 changes: 80 additions & 8 deletions src/components/PlayerSubmissionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,97 @@ class PlayerSubmissionForm extends Component {

constructor(props) {
super(props);
this.state = {
adjective: '',
noun: '',
adverb: '',
verb: '',
adverb2: '',
noun2: ''
}

this.baseState = this.state;
}

onInputChange = (e) => {
const field = e.target.name;
const value = e.target.value;
const newState = {};
newState[field] = value;

this.setState(newState);
}

onFormSubmit = (e) => {
e.preventDefault();

const poemLine = `The ${this.state.adjective} ${this.state.noun} ${this.state.adverb} ${this.state.verb} ${this.state.adverb2} ${this.state.noun2}.`;

this.setState(this.baseState);

this.props.addLine(poemLine);
}

render() {

const inputClass = {}
for (const field in this.state) {
inputClass[field] = `PlayerSubmissionForm__input${this.state[field] === "" ? "--invalid" : ""}`
}

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

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

<div className="PlayerSubmissionForm__poem-inputs">

{
// Put your form inputs here... We've put in one below as an example
}
<label>The</label>
<input
placeholder="hm..."
className={inputClass.adjective}
name="adjective"
placeholder="adjective"
value = {this.state.adjective}
onChange = {this.onInputChange}
type="text" />

<input
className={inputClass.noun}
name="noun"
placeholder="noun"
value = {this.state.noun}
onChange = {this.onInputChange}
type="text" />
<input
className={inputClass.adverb}
name="adverb"
placeholder="adverb"
value = {this.state.adverb}
onChange = {this.onInputChange}
type="text" />
<input
className={inputClass.verb}
name="verb"
placeholder="verb"
value = {this.state.verb}
onChange = {this.onInputChange}
type="text" />
<label>the</label>
<input
className={inputClass.adverb2}
name="adverb2"
placeholder="adverb"
value = {this.state.adverb2}
onChange = {this.onInputChange}
type="text" />
<input
className={inputClass.noun2}
name="noun2"
placeholder="noun"
value = {this.state.noun2}
onChange = {this.onInputChange}
type="text" />
<label>.</label>
</div>

<div className="PlayerSubmissionForm__submit">
Expand Down
5 changes: 4 additions & 1 deletion src/components/RecentSubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import React from 'react';
import './RecentSubmission.css';

const RecentSubmission = (props) => {

const recentLine = props.line ? props.line : '';

return (
<div className="RecentSubmission">
<h3>The Most Recent Submission</h3>
<p className="RecentSubmission__submission">{ }</p>
<p className="RecentSubmission__submission">{ recentLine }</p>
</div>
);
}
Expand Down