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- Schanen #48

Open
wants to merge 14 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
32 changes: 21 additions & 11 deletions src/components/FinalPoem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,28 @@ import './FinalPoem.css';

const FinalPoem = (props) => {

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" />
if (props.isSubmitted === true) {
return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
{props.submissions.map((submission, i) => (
<p key={i}>{submission}</p>
))}
</section>
</div>
</div>
);
)
} else {
return (
<div className="FinalPoem__reveal-btn-container">
<input
onClick={props.revealPoem}
type="button"
value="We are finished: Reveal the Poem"
className="FinalPoem__reveal-btn" />
</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
37 changes: 34 additions & 3 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import FinalPoem from './FinalPoem';
import RecentSubmission from './RecentSubmission';

const Game = () => {

const exampleFormat = FIELDS.map((field) => {
if (field.key) {
return field.placeholder;
Expand All @@ -13,6 +14,24 @@ const Game = () => {
}
}).join(' ');

const [player, setCurrentPlayer] = useState(1);
const [playerSubmission, setPlayerSubmission] = useState([]);
const[isSubmitted, setIsSubmitted] = useState(false);

const addPlayerSubmission = (submission) => {
const poem = [...playerSubmission];
poem.push(submission);
setPlayerSubmission(poem);
setCurrentPlayer(player + 1);
};


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

const lastSubmission = playerSubmission[playerSubmission.length - 1]

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

<RecentSubmission />
{!isSubmitted && lastSubmission &&
<RecentSubmission submission={lastSubmission} />
}

<PlayerSubmissionForm />
{!isSubmitted &&
<PlayerSubmissionForm
index={player}
fields={FIELDS}
sendSubmission={addPlayerSubmission}
/>
}

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

</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
8 changes: 8 additions & 0 deletions src/components/PlayerSubmissionForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@
.PlayerSubmissionForm__input--invalid::placeholder {
color: black;
}

.invalidInput {
background-color: pink;
}

.validInput {
background-color: white;
}
73 changes: 63 additions & 10 deletions src/components/PlayerSubmissionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,79 @@ import PropTypes from 'prop-types';

import './PlayerSubmissionForm.css';

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

const newFields = {
adj1: '',
noun1: '',
adverb: '',
verb: '',
adj2: '',
noun2: ''
};

const [currentFields, setCurrentFields] = useState (newFields);

const onFormChange = (event) => {
const newFormFields = {
...currentFields
}

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

const onFormSubmit = (event) => {
event.preventDefault();

const line = props.fields.map(field => {
const fieldsSubmitted = {...currentFields};

if (field.key) {
return fieldsSubmitted[field.key];
} else {
return field
}
}).join(' ');

props.sendSubmission(line);

setCurrentFields(newFields);
};

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

<form className="PlayerSubmissionForm__form" >
<h3>Player Submission Form for Player #{props.index}</h3>

<div className="PlayerSubmissionForm__poem-inputs">
<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
props.fields.map((field, i) => {
if (field.key) {
return(
<input
key={field.key}
name={field.key}
placeholder={field.placeholder}
onChange={onFormChange}
value={currentFields[field.key] || ''}
type='text'
className={currentFields[field.key] ? 'validInput' : 'invalidInput'}
/>)
} else {
return field;
}
})
}
<input
placeholder="hm..."
type="text" />

</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
3 changes: 1 addition & 2 deletions src/components/RecentSubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ 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>
);
}

RecentSubmission.propTypes = {
submission: PropTypes.string.isRequired,
};
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
Loading