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

Earth/Taylor #47

Open
wants to merge 6 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
42,432 changes: 33,231 additions & 9,201 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 18 additions & 8 deletions src/components/FinalPoem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ import './FinalPoem.css';

const FinalPoem = (props) => {

return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
const button =
<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" onClick={props.revealPoem} />
</div>

</section>
const completePoemLines = props.submissions.map((submission, index) => {
return <p key={index}>{submission}</p>
})

<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
</div>
const completePoem =
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
{completePoemLines}
</section>

const buttonOrPoem = props.isSubmitted ? completePoem : button

return (
<div className="FinalPoem">
{buttonOrPoem}
</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
40 changes: 36 additions & 4 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ const Game = () => {
}
}).join(' ');

const [submissions, setSubmissions] = useState([])
const [isSubmitted, setIsSubmitted] = useState(false)

const addSubmission = (submission) => {
setSubmissions([...submissions,submission])
}

const revealPoem = (event) => {
event.preventDefault();
setIsSubmitted(true);
}

const recentSubmission = isSubmitted ? '' : <RecentSubmission submission={ submissions[submissions.length - 1]} />

const playerForm = isSubmitted ? '' : <PlayerSubmissionForm
index={submissions.length + 1}
sendSubmission={addSubmission}
fields={FIELDS}
/>

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

<RecentSubmission />
{recentSubmission}

{playerForm}
{/*
<RecentSubmission submission={ submissions[submissions.length - 1]} />

<PlayerSubmissionForm />
<PlayerSubmissionForm
index={submissions.length + 1}
sendSubmission={addSubmission}
fields={FIELDS}
/> */}

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

</div>
);
}


const FIELDS = [
export const FIELDS = [
'The',
{
key: 'adj1',
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
76 changes: 64 additions & 12 deletions src/components/PlayerSubmissionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,78 @@ import PropTypes from 'prop-types';

import './PlayerSubmissionForm.css';

const PlayerSubmissionForm = () => {
const PlayerSubmissionForm = (props) => {

const emptyValues = {};
props.fields.forEach((field) => {
if (field.key) {
emptyValues[field.key] = '';
}
});

const [poemFields, setPoemFields] = useState(emptyValues)

const onInputChange = (value, name) => {
const newFields = {
...poemFields,
[name]: value
}

setPoemFields(newFields);
};

const isValid = (value) => {
return value.length > 0
}

const sendSubmission = (event) => {
event.preventDefault();
const submission = props.fields.map((field) => {
if (field.key) {
return poemFields[field.key];
} else {
return field;
}
});
props.sendSubmission(submission.join(' '));
setPoemFields(emptyValues)
}

const inputValues = props.fields.map((field) => {

Choose a reason for hiding this comment

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

Each item here needs a key attribute. You can wrap the strings in a span like this:

else {
  return <span key={field}> {field } </span>
}

Making sure each element in the array has a key will get rid of the warning you're seeing.

if (field.key) {
return <input
name={field.name}
placeholder={field.placeholder}
type="text"
onChange={(event) => {onInputChange(event.target.value, field.key)}}
value={poemFields[field.key]}
key={field.index}
className={isValid(poemFields[field.key]) ? 'PlayerSubmissionForm__poem-inputs' : 'PlayerSubmissionFormt__input--invalid'}
data-testid={field.name}
/>
} else {
return field;
}
});

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

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

<div className="PlayerSubmissionForm__poem-inputs">

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

{ inputValues }
</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"
/>
</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 @@ -6,7 +6,7 @@ const RecentSubmission = (props) => {
return (

Choose a reason for hiding this comment

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

Just note there's a prop submission that you're using here which is marked as required in propTypes, but it's not being used. Either remove it, or use the prop to get rid of the warning.

<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