Skip to content
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
42,404 changes: 33,207 additions & 9,197 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 28 additions & 10 deletions src/components/FinalPoem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,38 @@ import React from 'react';
import PropTypes from 'prop-types';
import './FinalPoem.css';

const FinalPoem = (props) => {
const FinalPoem = ({isSubmitted, submissions, revealPoem}) => {

return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
const prettyPrintPoem = submissions.map((poem, index) => ( // why couldn't I use {} here?
<p key={index}>{poem}</p>
));

</section>

<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
if (isSubmitted) {
return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
</section>
<div className="FinalPoem__reveal-btn-container">
<section>
{prettyPrintPoem}
</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={revealPoem}/>
</div>
</div>
);
);
}
}

FinalPoem.propTypes = {
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
24 changes: 21 additions & 3 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ const Game = () => {
}
}).join(' ');

const [submissionList, setSubmissionList] = useState([]);
const [player, setPlayer] = useState(1);
const [finalizePoem, setFinalizePoem] = useState(false);

const addSubmission = (submission) => {
const newSubmissionList = [...submissionList];
newSubmissionList.push(submission);

setSubmissionList(newSubmissionList);
setPlayer(player +1)
}

const lastSubmission = submissionList[submissionList.length-1];

const revealPoem = () => {
setFinalizePoem(true);
};

return (
<div className="Game">
<h2>Game</h2>
Expand All @@ -25,11 +43,11 @@ const Game = () => {
{ exampleFormat }
</p>

<RecentSubmission />
{ (submissionList.length !== 0) ? <RecentSubmission submission={lastSubmission} /> : <span /> }

<PlayerSubmissionForm />
{ (finalizePoem) ? <span /> : <PlayerSubmissionForm fields={FIELDS} sendSubmission={addSubmission} index={player} /> }

<FinalPoem />
<FinalPoem submissions={submissionList} isSubmitted={finalizePoem} revealPoem={revealPoem} />

</div>
);
Expand Down
6 changes: 3 additions & 3 deletions 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 Expand Up @@ -99,7 +99,7 @@ describe.skip('Game', () => {
});


describe('Wave 2: Showing lines of poetry', () => {
describe.skip('Wave 2: Showing lines of poetry', () => {

test('you can enter a line of the poem', () => {
const line = ['big', 'cat', 'abruptly', 'eats', 'tasty', 'dogfood'];
Expand Down Expand Up @@ -149,7 +149,7 @@ describe.skip('Game', () => {
});
});

describe('Wave 3, these test submitting a finished poem', () => {
describe.skip('Wave 3, these test submitting a finished poem', () => {
test('you can click on the "We are finished: Reveal the Poem" button', () => {
// Arrange
// Submit the poem
Expand Down
4 changes: 4 additions & 0 deletions src/components/PlayerSubmissionForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@
.PlayerSubmissionForm__input--invalid::placeholder {
color: black;
}

.unbulleted-List {
list-style: none;
}
83 changes: 74 additions & 9 deletions src/components/PlayerSubmissionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,87 @@ import PropTypes from 'prop-types';

import './PlayerSubmissionForm.css';

const PlayerSubmissionForm = () => {
const PlayerSubmissionForm = ({fields, sendSubmission, index}) => {

const [formFields, setFormFields] = useState({
adj1: '',
noun1: '',
adv: '',
verb: '',
adj2: '',
noun2: ''
});

const onInputChange = (event) => {
// console.log(`Changing field ${ event.target.name } to ${ event.target.value }`);
// Duplicate formFields into new object
const newFormFields = {
...formFields,
}

newFormFields[event.target.name] = event.target.value;
setFormFields(newFormFields);
}

const onFormSubmit = (event) => {
// prevent the browser from trying to submit the form.
event.preventDefault();

const submission = fields.map(field => {
const submittedFields = {...formFields};
if (field.key) {
return submittedFields[field.key]
} else {
return field
}
}).join(' ');

sendSubmission(submission);

// reset form fields
setFormFields({
adj1: '',
noun1: '',
adv: '',
verb: '',
adj2: '',
noun2: ''
});
};

const inputValid = (field) => {
return formFields[field.key] !== '';
};

const generateInputFields = fields.map((field, index) => {
if (field.key) {
return <li key={index} className='unbulleted-List'>
<input
name={field.key}
placeholder={field.placeholder}
value={formFields[field.key] || ''}
onChange={onInputChange}
className={inputValid(field) ? '' : 'PlayerSubmissionFormt__input--invalid'}
type="text" />
</li>;
}
else {
return <li key={index} className='unbulleted-List'>
<span>{field}</span>
</li>
}
});

return (
<div className="PlayerSubmissionForm">
<h3>Player Submission Form for Player #{ }</h3>
<h3>Player Submission Form for Player #{index}</h3>

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

<div className="PlayerSubmissionForm__poem-inputs">

{
// Put your form inputs here... We've put in one below as an example
generateInputFields
}
<input
placeholder="hm..."
type="text" />

</div>

<div className="PlayerSubmissionForm__submit">
Expand Down
5 changes: 4 additions & 1 deletion src/components/RecentSubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import PropTypes from 'prop-types';
import './RecentSubmission.css';

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