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 - Carla #25

Open
wants to merge 7 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
22 changes: 15 additions & 7 deletions src/components/FinalPoem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ import React from 'react';
import './FinalPoem.css';

const FinalPoem = (props) => {

const finalPoem = props.poem.map((verse, index) => {
return (<p key={index}>{verse}</p>)
})

return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
{ props.finalized &&
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
{finalPoem}
</section>
}

</section>

<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
</div>
{ !props.finalized && finalPoem.length >= 1 &&
<div className="FinalPoem__reveal-btn-container">
<input onClick={props.revealPoemCallback} type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
</div>
}
</div>
);
}
Expand Down
47 changes: 43 additions & 4 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,38 @@ class Game extends Component {

constructor(props) {
super(props);

this.state = {
poem: [],
finalized: false,
}
}

addVerse = (newVerse) => {
const newState = {...this.state}
const updatedPoem = newState.poem
updatedPoem.push(newVerse)
this.setState(updatedPoem)
}

finalizePoem = () => {
if (this.state.poem.length >= 1) {
this.setState({finalized: true})
}
}

render() {

const showMostRecent = () => {
if (this.state.poem.length >= 1 && !this.state.finalized) {
return <RecentSubmission
poem={this.state.poem}
/>
}
}

const playerNumber = this.state.poem.length

const exampleFormat = FIELDS.map((field) => {
if (field.key) {
return field.placeholder;
Expand All @@ -32,11 +60,22 @@ class Game extends Component {
{ exampleFormat }
</p>

<RecentSubmission />

<PlayerSubmissionForm />
{ showMostRecent() }

<FinalPoem />

{ !this.state.finalized &&
<PlayerSubmissionForm
fields={FIELDS}
playerNumber={playerNumber}
formCallback={this.addVerse}
/>
}

<FinalPoem
poem={this.state.poem}
finalized={this.state.finalized}
revealPoemCallback={this.finalizePoem}
/>

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

class PlayerSubmissionForm extends Component {

constructor(props) {
super(props);

this.state = {
adj1: '',
noun1: '',
adv: '',
verb: '',
adj2: '',
noun2: '',
}
}

resetState = () => {
this.setState({
adj1: '',
noun1: '',
adv: '',
verb: '',
adj2: '',
noun2: '',
})
}

onFormChange = (event) => {
const field = event.target.name;
const value = event.target.value;

const updatedState = {};
updatedState[field] = value;
this.setState(updatedState);
}

onSubmit = (event) => {
event.preventDefault()
// const {adjective1, noun1, adverb, verb, adjective2, noun2} = this.state

const newVerse = this.props.fields.map((field) => {
if (field.key) {
return this.state[field.key]
} else {
return field
}
})
console.log(event)
this.props.formCallback(newVerse.join(" "))

this.resetState()
}

isInputValid = (input) => {
const className = input.length > 0 ? '' : 'PlayerSubmissionFormt__input--invalid'
return className
}



render() {

return (
<div className="PlayerSubmissionForm">
<h3>Player Submission Form for Player #{ }</h3>
{/* Add 1 so it does not start from player #0 */}
<h3>Player Submission Form for Player #{ this.props.playerNumber + 1}</h3>

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

<div className="PlayerSubmissionForm__poem-inputs">

{
// Put your form inputs here... We've put in one below as an example
}
<input
placeholder="hm..."
type="text" />
<div>
The <input className={this.isInputValid(this.state.adj1)} name='adj1' type="text" placeholder='adjective' onChange={this.onFormChange} value={this.state.adj1}/>
</div>
<div>
<input className={this.isInputValid(this.state.noun1)} name='noun1' type="text" placeholder='noun' onChange={this.onFormChange} value={this.state.noun1}/>
</div>
<div>
<input className={this.isInputValid(this.state.adv)} name='adv' type="text" placeholder='adverb' onChange={this.onFormChange} value={this.state.adv}/>
</div>
<div>
<input className={this.isInputValid(this.state.verb)} name='verb' type="text" placeholder='verb' onChange={this.onFormChange} value={this.state.verb}/>
</div>
<div>
the <input className={this.isInputValid(this.state.adj2)} name='adj2' type="text" placeholder='adjective' onChange={this.onFormChange} value={this.state.adj2}/>
</div>
<div>
<input className={this.isInputValid(this.state.noun2)} name='noun2' type="text" placeholder='noun' onChange={this.onFormChange} value={this.state.noun2}/>
</div>

</div>

Expand All @@ -35,4 +101,10 @@ class PlayerSubmissionForm extends Component {
}
}


PlayerSubmissionForm.propTypes = {
formCallback: PropTypes.func.isRequired,
playerNumber: PropTypes.number.isRequired,
}

export default PlayerSubmissionForm;
6 changes: 5 additions & 1 deletion src/components/RecentSubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import React from 'react';
import './RecentSubmission.css';

const RecentSubmission = (props) => {
const finalPoem = props.poem.map((verse, index) => {
return (<p key={index}>{verse}</p>)
})

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