-
Notifications
You must be signed in to change notification settings - Fork 51
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
Water @ Hanh Solo Exquisite React Submission #46
base: master
Are you sure you want to change the base?
Changes from all commits
914f35d
47a9172
a744ca9
0a781f0
5623e1f
6c329fd
3fc69ff
f8c02a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,24 +1,106 @@ | ||||||
import React, { useState } from 'react'; | ||||||
import PropTypes from 'prop-types'; | ||||||
|
||||||
import './PlayerSubmissionForm.css'; | ||||||
|
||||||
const PlayerSubmissionForm = () => { | ||||||
const PlayerSubmissionForm = (props) => { | ||||||
const setInitialState = () => { | ||||||
const initialStateValue = {}; //this is an object with an ability to set key like hash | ||||||
for ( const field of props.fields ) { | ||||||
if (field.key) {// if this is true | ||||||
initialStateValue[field.key] = ''; //set key and value | ||||||
} | ||||||
} | ||||||
return initialStateValue; | ||||||
|
||||||
} | ||||||
|
||||||
const [words, updateWords] = useState(setInitialState()); | ||||||
|
||||||
/*event handlers/listeners*/ | ||||||
//this is how the form is gathering and building up data for form | ||||||
const onInputChange = (event) => { | ||||||
|
||||||
const newPlayerSubmission = { | ||||||
...words | ||||||
}; | ||||||
|
||||||
const { name, value } = event.target | ||||||
|
||||||
// This sets newformFields to the old value of the form state | ||||||
// and then updates the one field that changed. | ||||||
newPlayerSubmission[name] = value; // updated the value using the hash key | ||||||
updateWords(newPlayerSubmission); // updated the form with new values | ||||||
} | ||||||
|
||||||
//This is the finished data being passed to game | ||||||
const onFormWordSubmission = (event) => { | ||||||
// prevent the form from being submitted | ||||||
event.preventDefault(); | ||||||
// print user data | ||||||
console.log(words); | ||||||
// pass data to Game-callback function-your submission is ready | ||||||
props.sendSubmission(words) | ||||||
// clear the submission, get ready for the next player | ||||||
updateWords(setInitialState()); | ||||||
}; | ||||||
|
||||||
return ( | ||||||
<div className="PlayerSubmissionForm"> | ||||||
<h3>Player Submission Form for Player #{ }</h3> | ||||||
|
||||||
<form className="PlayerSubmissionForm__form" > | ||||||
<h3>Player Submission Form for Player # { props.index }</h3> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will cause all the tests in
Suggested change
|
||||||
|
||||||
<form className="PlayerSubmissionForm__form" onSubmit={onFormWordSubmission}> | ||||||
<div className="PlayerSubmissionForm__poem-inputs"> | ||||||
|
||||||
{ | ||||||
// Put your form inputs here... We've put in one below as an example | ||||||
} | ||||||
<p>The</p> | ||||||
<input | ||||||
placeholder="hm..." | ||||||
type="text" /> | ||||||
|
||||||
placeholder="adjective" | ||||||
type="text" | ||||||
name='adj1' | ||||||
value={ words.adj1 } | ||||||
onChange={ onInputChange } | ||||||
className={ !words.adj1.length ? 'PlayerSubmissionFormt__input--invalid' : '' } | ||||||
/> | ||||||
<input | ||||||
placeholder="noun" | ||||||
type="text" | ||||||
name='noun1' | ||||||
value={ words.noun1 } | ||||||
onChange={ onInputChange } | ||||||
className={ !words.noun1.length ? 'PlayerSubmissionFormt__input--invalid' : '' } | ||||||
/> | ||||||
<input | ||||||
placeholder="adverb" | ||||||
type="text" | ||||||
name='adv' | ||||||
value={ words.adv } | ||||||
onChange={ onInputChange } | ||||||
className={ !words.adv.length ? 'PlayerSubmissionFormt__input--invalid' : '' } | ||||||
/> | ||||||
<input | ||||||
placeholder="verb" | ||||||
type="text" | ||||||
name='verb' | ||||||
value={ words.verb } | ||||||
onChange={ onInputChange } | ||||||
className={ !words.verb.length ? 'PlayerSubmissionFormt__input--invalid' : '' } | ||||||
/> | ||||||
<p>the</p> | ||||||
<input | ||||||
placeholder="adjective" | ||||||
type="text" | ||||||
name='adj2' | ||||||
value={ words.adj2 } | ||||||
onChange={ onInputChange } | ||||||
className={ !words.adj2.length ? 'PlayerSubmissionFormt__input--invalid' : '' } | ||||||
/> | ||||||
<input | ||||||
placeholder="noun" | ||||||
type="text" | ||||||
name='noun2' | ||||||
value={ words.noun2 } | ||||||
onChange={ onInputChange } | ||||||
className={ !words.noun2.length ? 'PlayerSubmissionFormt__input--invalid' : '' } | ||||||
/> | ||||||
<p>.</p> | ||||||
</div> | ||||||
|
||||||
<div className="PlayerSubmissionForm__submit"> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,17 @@ import PropTypes from 'prop-types'; | |
import './RecentSubmission.css'; | ||
|
||
const RecentSubmission = (props) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to note the tests for this component are passing, so you didn't need to skip them. |
||
return ( | ||
<div className="RecentSubmission"> | ||
<h3>The Most Recent Submission</h3> | ||
<p className="RecentSubmission__submission">{ }</p> | ||
</div> | ||
); | ||
} | ||
if (props.submission) { | ||
return ( | ||
<div className="RecentSubmission"> | ||
<h3>The Most Recent Submission</h3> | ||
<p className="RecentSubmission__submission">{ props.submission }</p> | ||
</div> | ||
); | ||
} else { | ||
return (null) | ||
} | ||
}; | ||
|
||
RecentSubmission.propTypes = { | ||
submission: PropTypes.string.isRequired, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const FinalPoem = (props) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what this file is for. |
||
|
||
if (props.isRevealed) { | ||
|
||
//event handler | ||
const showButton= (event) => { | ||
|
||
return ( | ||
<div className="FinalPoem"> | ||
<section className="FinalPoem__poem"> | ||
<h3>Final Poem</h3> | ||
</section> | ||
|
||
<div className="FinalPoem__reveal-btn-container"> | ||
<input | ||
type="button" value="We are finished: Reveal the Poem" | ||
className="FinalPoem__reveal-btn" | ||
onClick={ props.revealPoem } | ||
/> | ||
<section> | ||
{(props.submissions).map((string, index) => ( | ||
<p key={index}> | ||
{string} | ||
</p> | ||
))} | ||
</section> | ||
</div> | ||
</div> | ||
)} | ||
else { | ||
return( | ||
<div className="FinalPoem"> | ||
<section className="FinalPoem__poem"> | ||
<h3>Final Poem</h3> | ||
</section> | ||
|
||
<div className="FinalPoem__reveal-btn-container"> | ||
<input | ||
type="button" value="We are finished: Reveal the Poem" | ||
className="FinalPoem__reveal-btn" | ||
onClick={ props.revealPoem } | ||
/> | ||
</div> | ||
</div> | ||
)} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note that it looks like the tests are failing because you used different props like
isRevealed
instead ofisSubmitted
. That's why it looks like the tests are failing.