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 - Myriam #22

Open
wants to merge 5 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
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"object-set-all-values-to": "^3.9.25",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"react-scripts": "3.0.1"
Expand Down
21 changes: 19 additions & 2 deletions src/components/FinalPoem.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import React from 'react';
import './FinalPoem.css';



const FinalPoem = (props) => {

const onClickFinalPoem = () =>{

props.onFinalPoemButtonCallback();

}


console.log(props.poem)

const lines = function () {
if (props.clicked){
return props.poem.map((poem, index) => <p key={index}>{poem}</p>)
}
}

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

{lines()}
</section>

<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
<input type="button" value={props.value} className="FinalPoem__reveal-btn" onClick={onClickFinalPoem}/>
</div>
</div>
);
Expand Down
92 changes: 89 additions & 3 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,88 @@ import PlayerSubmissionForm from './PlayerSubmissionForm';
import FinalPoem from './FinalPoem';
import RecentSubmission from './RecentSubmission';


class Game extends Component {

constructor(props) {
super(props);
this.state = INITIAL_STATE;
}

renderRecentSubmission() {
if(this.state.mostRencentSubmission !== '' && this.state.finalPoemClicked === false) {
return (
<RecentSubmission mostRecentSubmission={this.state.mostRencentSubmission}/>
)
}
}

renderPlayerSubmissionForm(){
if(this.state.finalPoemClicked === false){
return (
<PlayerSubmissionForm onPlayerFormButtonCallback={this.onPlayerFormButton} fields={FIELDS}/>
)
}
}

renderFinalPoem(){

console.log(this.state.finalPoem)
return(
<FinalPoem value={this.state.finalPoemButtonValue} onFinalPoemButtonCallback={this.onFinalPoemButton} poem={this.state.finalPoem} clicked={this.state.finalPoemClicked}/>
)
}

onPlayerFormButton = (event, submission) => {

event.preventDefault();

let last = ''

Object.keys(submission).map(function(key){

if(key === 'adj1'){
last += 'The '
} else if (key === 'adj2') {
last += 'the'
}
return (last += submission[key] + ' ')

})

const newFinalPoem = [
...this.state.finalPoem,
last
];
this.setState({
finalPoem: newFinalPoem,
mostRencentSubmission: last,
})

this.renderPlayerSubmissionForm()

}

onFinalPoemButton = () => {

console.log(this.state.finalPoem)

let clicked;
let value = ''


if (this.state.finalPoemClicked === false) {

clicked = true
value = "Play again!"

}

this.setState(!clicked ? INITIAL_STATE : {
finalPoemClicked: clicked,
finalPoemButtonValue: value,
})

}

render() {
Expand All @@ -32,17 +110,25 @@ class Game extends Component {
{ exampleFormat }
</p>

<RecentSubmission />
{this.renderRecentSubmission()}

<PlayerSubmissionForm />
{this.renderPlayerSubmissionForm()}

<FinalPoem />
{this.renderFinalPoem()}

</div>
);
}
}

const INITIAL_STATE = {
mostRencentSubmission: '',
finalPoem: [],
poem: '',
finalPoemClicked: false,
finalPoemButtonValue: "We are finished: Reveal the Poem",
};

const FIELDS = [
"The",
{
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
86 changes: 75 additions & 11 deletions src/components/PlayerSubmissionForm.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,97 @@
import React, { Component } from 'react';
import './PlayerSubmissionForm.css';
import setAllValuesTo from "object-set-all-values-to";

class PlayerSubmissionForm extends Component {

constructor(props) {
super(props);
this.state = {
submission: {
adj1: '',
noun1: '',
adv: '',
verb: '',
adj2: '', noun2: ''
},
fullSubmission: '',
name: '',
turn: 1,
inputClassName: '--invalid'
}
}

onChangeInput = (event) => {

event.target.className = "PlayerSubmissionForm__input";

let submission = {
...this.state.submission,
[event.target.name]: event.target.value
};

this.setState({
submission
});

console.log(submission)

}

onSubmitForm = (event) => {
event.preventDefault();
const{
submission,
turn
} = this.state;
this.props.onPlayerFormButtonCallback(event, submission);
let newSub = setAllValuesTo(submission, '');
console.log(newSub === submission);
this.setState({
submission: setAllValuesTo(submission, '') ,
fullSubmission: '',
turn: turn + 1,
})
}



render() {

let formFields = this.props.fields.map(field => {
if (typeof field === "string") {
return field;
} else {
const {
key,
placeholder
} = field;
return (
<input
key={key}
className="PlayerSubmissionForm__input--invalid"
name={key}
placeholder={placeholder}
value={this.state.submission[key]}
type="text" onChange={this.onChangeInput}
/>
);
}

})

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

<form 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" />

{ formFields }
</div>

<div className="PlayerSubmissionForm__submit">
<input type="submit" value="Submit Line" className="PlayerSubmissionForm__submit-btn" />
<input type="submit" value="Submit Line" className="PlayerSubmissionForm__submit-btn" onClick={this.onSubmitForm}/>
</div>
</form>
</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.mostRecentSubmission }</p>
</div>
);
}
Expand Down