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 - Sophie #25

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
43,421 changes: 34,120 additions & 9,301 deletions package-lock.json

Large diffs are not rendered by default.

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

const FinalPoem = (props) => {

return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
const FinalPoem = (props) => {

</section>
const clickHandler = () => {
props.revealPoem()
}

if (props.isSubmitted === true) {
return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
<ol>
{props.submissions.map(submission => (
<li key={submission}>{submission}</li>
))}
</ol>
</section>
</div>
)
} else {
return(
<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
<input type="button"
value="We are finished: Reveal the Poem"
className="FinalPoem__reveal-btn"
onClick={clickHandler}/>
</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
53 changes: 42 additions & 11 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ const Game = () => {
}
}).join(' ');


// Wave 1 - Handle Submissions
const [submissions, setSubmissions] = useState([])

const [isSubmitted, setSubmittedStatus] = useState(false)

const sendSubmission = (formFields) => {

const submission = formFields.map(field => {
if (field.key) {
return field.userInput;
} else {
return field;
}
}).join(' ');

setSubmissions([...submissions, submission])
}

// Wave 2 - Final Poem
const revealPoem = () => {
setSubmittedStatus(true)
}


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

<RecentSubmission />
<RecentSubmission submission={submissions[submissions.length - 1] || ''}/>

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

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

</div>
);
} else {
return (
<FinalPoem isSubmitted={isSubmitted} submissions={submissions} revealPoem={revealPoem} />
)
}
}


const FIELDS = [
'The',
{
key: 'adj1',
placeholder: 'adjective',
placeholder: 'adjective1',
},
{
key: 'noun1',
placeholder: 'noun',
placeholder: 'noun1',
},
{
key: 'adv',
placeholder: 'adverb',
key: 'adverb1',
placeholder: 'adverb1',
},
{
key: 'verb',
placeholder: 'verb',
key: 'verb1',
placeholder: 'verb1',
},
'the',
{
key: 'adj2',
placeholder: 'adjective',
placeholder: 'adjective2',
},
{
key: 'noun2',
placeholder: 'noun',
placeholder: 'noun2',
},
'.',
];
Expand Down
19 changes: 10 additions & 9 deletions src/components/Game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ const FIELDS = [
'The',
{
key: 'adj1',
placeholder: 'adjective',
placeholder: 'adjective1',
},
{
key: 'noun1',
placeholder: 'noun',
placeholder: 'noun1',
},
{
key: 'adv',
placeholder: 'adverb',
key: 'adverb1',
placeholder: 'adverb1',
},
{
key: 'verb',
placeholder: 'verb',
key: 'verb1',
placeholder: 'verb1',
},
'the',
{
key: 'adj2',
placeholder: 'adjective',
placeholder: 'adjective2',
},
{
key: 'noun2',
placeholder: 'noun',
placeholder: 'noun2',
},
'.',
];

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

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

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

Expand Down Expand Up @@ -165,6 +165,7 @@ describe.skip('Game', () => {
});

test('Adding 2 lines to the poem and then revealing it', () => {

const line1 = ['big', 'cat', 'abruptly', 'eats', 'tasty', 'dogfood'];
const line2 = ['small', 'pooch', 'slowly', 'whines', 'annoying', 'pest'];

Expand Down
61 changes: 50 additions & 11 deletions src/components/PlayerSubmissionForm.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,67 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';

import './PlayerSubmissionForm.css';
import _ from 'lodash';

const PlayerSubmissionForm = (props) => {

const newFields = props.fields.map((field) => {
if (field.key) {
return {...field, userInput: ''}
} else {
return field
}
})

const [formFields, setFormFields] = useState(newFields)

const resetFields = () => {
setFormFields(newFields)
}

const onFieldChange = (i, event) => {
const newFormData = _.cloneDeep(formFields) // make a deep copy
newFormData[i] = {...newFormData[i], userInput: event.target.value};
setFormFields(newFormData)
}

const generateFormFields = formFields.map((field, i) => {
if(field.key) {
return(
<input
key={i}
name={field.key}
placeholder={field.placeholder}
value={field.userInput}
onChange={(event)=>{onFieldChange(i, event)}}
type="text"
/>
)
} else {
return (field)
}
})

const submitHandler = (event) => {
event.preventDefault()
props.sendSubmission(formFields)
resetFields()
}

const PlayerSubmissionForm = () => {
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={submitHandler}>

<div className="PlayerSubmissionForm__poem-inputs">

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

</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
17 changes: 11 additions & 6 deletions src/components/RecentSubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ 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>
</div>
);

if(props.submission) {
return(
<div className="RecentSubmission">
<h3>The Most Recent Submission</h3>
<p className="RecentSubmission__submission">{ props.submission }</p>
</div>
)
} else {
return (<h3>Greetings.</h3>)
}
}

RecentSubmission.propTypes = {
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