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

Fire | Ayesha - Exquisite react submission #43

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
13,316 changes: 6,967 additions & 6,349 deletions package-lock.json

Large diffs are not rendered by default.

29 changes: 21 additions & 8 deletions src/components/FinalPoem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@ import PropTypes from 'prop-types';
import './FinalPoem.css';

const FinalPoem = (props) => {
const onClickCallback = (event) => {
event.preventDefault();
props.revealPoem();
}
const finishedPoem =
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
{props.submissions.map((element, i) => {
return(<p key={i}>{element}</p>)
})}
</section>

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

</section>
const poemButton =
<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" onClick={onClickCallback} />
</div>


<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
const display = props.isSubmitted ? finishedPoem : poemButton

return (
<div className="FinalPoem">
{display}
</div>
</div>
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/FinalPoem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import userEvent from '@testing-library/user-event';

import FinalPoem from './FinalPoem';

describe.skip('FinalPoem', () => {
describe('FinalPoem', () => {
describe('before the poem is finished', () => {
test('it renders with a button when isSubmitted is false', () => {
// Act
Expand Down
23 changes: 19 additions & 4 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import FinalPoem from './FinalPoem';
import RecentSubmission from './RecentSubmission';

const Game = () => {
const [submittedLines, setSubmittedLines] = useState([])
const [submitted, setSubmitted] = useState(false)
const exampleFormat = FIELDS.map((field) => {
if (field.key) {
return field.placeholder;
Expand All @@ -13,6 +15,19 @@ const Game = () => {
}
}).join(' ');

const onSubmitLine = (submittedLine) => {
const newLineList = [...submittedLines, submittedLine];
setSubmittedLines(newLineList);

}
const getLastLine = () => {
return( (submittedLines.length > 0) ? submittedLines[submittedLines.length - 1] : '');
}
const finishGame = () => {
setSubmitted(!submitted);
}
const showRecentSubmission = (!submitted && submittedLines.length > 0) ? <RecentSubmission submission={ getLastLine() } /> : ''
const showSubmissionForm = (!submitted) ? <PlayerSubmissionForm fields={FIELDS} sendSubmission={onSubmitLine} index={0}/> : ''
return (
<div className="Game">
<h2>Game</h2>
Expand All @@ -25,11 +40,11 @@ const Game = () => {
{ exampleFormat }
</p>

<RecentSubmission />

<PlayerSubmissionForm />
{showRecentSubmission}

<FinalPoem />
{showSubmissionForm}

<FinalPoem isSubmitted={submitted} submissions={submittedLines} revealPoem={finishGame} />

</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const FIELDS = [

const INPUT_FIELDS = FIELDS.filter((element) => typeof element !== 'string');

describe.skip('Game', () => {
describe('Game', () => {

describe('Wave 1: Rendering Game', () => {

Expand Down
4 changes: 4 additions & 0 deletions src/components/PlayerSubmissionForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
justify-content: center;
}

input.empty {
background: gray;
}

.PlayerSubmissionForm__submit-btn {
flex: 0.5;
margin: 2rem;
Expand Down
55 changes: 48 additions & 7 deletions src/components/PlayerSubmissionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,62 @@ import PropTypes from 'prop-types';

import './PlayerSubmissionForm.css';

const PlayerSubmissionForm = () => {
const PlayerSubmissionForm = (props) => {
const blankFields = {
adj1: '',
noun1: '',
adv: '',
verb: '',
adj2: '',
noun2: '',
}

const [player, setPlayer] = useState(1);
const [playerSubmission, setPlayerSubmission] = useState(blankFields)
const onInputChange = (event) => {

const updatedField = {...playerSubmission}
updatedField[event.target.name] = event.target.value
setPlayerSubmission(updatedField)

}
const makeSentence = () => {
const words = props.fields.map((element) => {
if (element.key) {
return playerSubmission[`${element.key}`]
} else {
return element
}
})
return words.join(' ')
}
const onSubmitNewLine = (event) => {
event.preventDefault();

setPlayer(player + 1);
console.log(player);

props.sendSubmission(makeSentence());

setPlayerSubmission(blankFields);
}
return (
<div className="PlayerSubmissionForm">
<h3>Player Submission Form for Player #{ }</h3>
<h3>Player Submission Form for Player #{player}</h3>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note, that the test assumes the index prop determines which player's turn it is. That's why that test is failing.


<form className="PlayerSubmissionForm__form" >
<form className="PlayerSubmissionForm__form" onSubmit={onSubmitNewLine} >

<div className="PlayerSubmissionForm__poem-inputs">

{
// Put your form inputs here... We've put in one below as an example
props.fields.map((element, i) => {
if (element.key) {
return(<input key={ `${i}` } className={ playerSubmission[element.key] === '' ? 'empty' : 'full' } name={ element.key } placeholder={ element.placeholder } type="text" value={ playerSubmission[element.key] } onChange={ onInputChange } />)
} else {
return(element)
}
})
}
<input
placeholder="hm..."
type="text" />

</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 @@ -6,7 +6,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
2 changes: 1 addition & 1 deletion src/components/RecentSubmission.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { render, screen } from '@testing-library/react';
import RecentSubmission from './RecentSubmission';


describe.skip('Wave 2: RecentSubmission', () => {
describe('Wave 2: RecentSubmission', () => {
test('It renders with a submission and shows the text', () => {
// Act
render(<RecentSubmission submission={'This is a submission'} />);
Expand Down