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

Sockets - Amy #27

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
31 changes: 23 additions & 8 deletions src/components/FinalPoem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,31 @@ import './FinalPoem.css';

const FinalPoem = (props) => {

return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
const showPoemButton =
<div className="FinalPoem__reveal-btn-container">
<input
type="button"
value="We are finished: Reveal the Poem"
className="FinalPoem__reveal-btn"
onClick={props.showFinalPoem}
/>
</div>;

const finalPoemLines = props.submissions.map((line, i) => {
return <p key={i}>{line}</p>;
});

</section>
const finalPoem =
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
{finalPoemLines}
</section>;

<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
</div>
const gameDisplay = props.poemFinished ? finalPoem : showPoemButton;

return (
<div className="FinalPoem">
{gameDisplay}
</div>
);
}
Expand Down
40 changes: 35 additions & 5 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,31 @@ class Game extends Component {

constructor(props) {
super(props);

this.state = {
submissions: [],
poemFinished: false
};
}

render() {
addNewLine = (line) => {
const newSubmission = this.state.submissions;
newSubmission.push(line);

this.setState({
submissions: newSubmission,
})
};

showFinalPoem = (event) => {
event.preventDefault();

this.setState({
poemFinished: true
})
}

render() {
const exampleFormat = FIELDS.map((field) => {
if (field.key) {
return field.placeholder;
Expand All @@ -29,14 +50,23 @@ class Game extends Component {
<p>Please follow the following format for your poetry submission:</p>

<p className="Game__format-example">
{ exampleFormat }
{exampleFormat}
</p>

<RecentSubmission />
<RecentSubmission
submission={this.state.submissions[this.state.submissions.length - 1]}
/>

<PlayerSubmissionForm />
<PlayerSubmissionForm
fields={FIELDS}
addNewLineCallback={this.addNewLine}
/>

<FinalPoem />
<FinalPoem
poemFinished={this.state.poemFinished}
submissions={this.state.submissions}
showFinalPoem={this.showFinalPoem}
/>

</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/PlayerSubmissionForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
background-color: tomato;
}

.PlayerSubmissionFormt__input--invalid {
.PlayerSubmissionForm__input--invalid {
background-color: #FFE9E9;
}

Expand Down
96 changes: 81 additions & 15 deletions src/components/PlayerSubmissionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,98 @@ class PlayerSubmissionForm extends Component {

constructor(props) {
super(props);

const initialState = {
player: 1
};
props.fields.forEach((field) => {
if (field.key) {
initialState[field.key] = "";
}
});
this.state = initialState;
}

render() {
onValueChange = (event) => {
console.log(`${event.target} Updated ${event.target.value}`);

return (
<div className="PlayerSubmissionForm">
<h3>Player Submission Form for Player #{ }</h3>
const fields = {};
fields[event.target.name] = event.target.value;
this.setState(fields);
}

<form className="PlayerSubmissionForm__form" >
resetForm = () => {
const clearedState = {};
this.props.fields.forEach((field) => {
if (field.key) {
clearedState[field.key] = "";
}
});
this.setState(clearedState);
}

<div className="PlayerSubmissionForm__poem-inputs">
onFormSubmit = (event) => {
event.preventDefault();

{
// Put your form inputs here... We've put in one below as an example
}
<input
placeholder="hm..."
type="text" />
let newSubmission = "";
this.props.fields.forEach((field) => {
if (field.key) {
newSubmission += this.state[field.key];
} else {
return field;
}
return newSubmission;
});

</div>
let playerNumber = this.state.player;
playerNumber += 1

this.setState({
player: playerNumber
})
this.props.addNewLineCallback(newSubmission);
this.resetForm();
}

render() {

const formFields = this.props.fields.map((field, i) => {
if (field.key) {
return <input
key={i}
name={field.key}
placeholder={field.placeholder}
value={this.state[field.key]}
onChange={this.onValueChange}
type="text"
className={this.state[field.key].length > 0 ? "" : "PlayerSubmissionForm__input--invalid"}
/>;
} else {
return field;
}
})


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

<form
className="PlayerSubmissionForm"
onSubmit={this.onFormSubmit} >
<div className="PlayerSubmissionForm__inputs" >
{formFields}
</div>
<div className="PlayerSubmissionForm__submit">
<input type="submit" value="Submit Line" className="PlayerSubmissionForm__submit-btn" />
<input
name="submit"
type="submit"
className="PlayerSubmissionForm__submit-btn"
value="Submit Line"
/>
</div>
</form>
</div>
</div >
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/RecentSubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const RecentSubmission = (props) => {
return (
<div className="RecentSubmission">
<h3>The Most Recent Submission</h3>
<p className="RecentSubmission__submission">{ }</p>
<p className="RecentSubmission__submission">{ props.submission }</p>
</div>
);
}
Expand Down