Skip to content

Earth - Kal #35

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

Open
wants to merge 10 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.

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

const FinalPoem = (props) => {
const submittedPoem = props.submissions.map((line, i) => {
return(
<p key={i}>{line}</p>
)
})

const onRevealPoemButtonClick = () => {
props.revealPoem();
}

return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
const revealPoem =
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
{submittedPoem}
</section>;

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

<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
</div>
</div>
const content = props.isSubmitted ? revealPoem : revealPoemButton;

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

FinalPoem.propTypes = {
isSubmitted: PropTypes.bool.isRequired,
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
20 changes: 20 additions & 0 deletions src/components/Game.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,23 @@
text-align: center;
font-style: italic;
}

.ResetGame-btn-container {
display: flex;
justify-content: center;
margin: 2rem;
width: 200px;
}

.ResetGame-btn-container {
flex: 0.8;

padding: 1rem;
border: 2px black solid;
box-shadow: 5px 10px black;
transition: 0.25s;
}

.ResetGame-btn-container:hover {
background-color: tomato;
}
22 changes: 19 additions & 3 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import FinalPoem from './FinalPoem';
import RecentSubmission from './RecentSubmission';

const Game = () => {

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

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

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

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

return (
<div className="Game">
<h2>Game</h2>
Expand All @@ -24,12 +36,16 @@ const Game = () => {
<p className="Game__format-example">
{ exampleFormat }
</p>

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

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

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

<FinalPoem />
<div className="ResetGame-btn-container" >
<input type="button" value="Reset Game" className="ResetGame-btn" onClick={revealPoem}/>
</div>

</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 @@ -38,3 +38,7 @@
.PlayerSubmissionForm__input--invalid::placeholder {
color: black;
}

.bad {
background-color: red;
}
79 changes: 70 additions & 9 deletions src/components/PlayerSubmissionForm.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,85 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';

import './PlayerSubmissionForm.css';

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

Choose a reason for hiding this comment

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

Just a note you're getting a warning when the application runs (when you type in a textbox) here because the original value of the forms are undefined and then when the user types in them they get set.

It's because the keys in props.fields, don't match the keys in wordFields.

const [wordFields, setWordFields] = useState({
adjOne: '',
nounOne: '',
adverb: '',
verb: '',
adjTwo: '',
nounTwo: ''
})

const onInputChange = (event) => {
console.log(`Changing field ${ event.target.name } to ${ event.target.value }`);
const newWordFields = {
...wordFields,
}

newWordFields[event.target.name] = event.target.value;
setWordFields(newWordFields);
}

const isValid = (val) => {
return val && val.length
}

const formSubmission = () => props.fields.map(field => {
if (typeof field === 'object') {
return wordFields[field.key]
}
return field
}).join(' ')

const onFormSubmit = (event) => { // stops browser from trying to submit the form

event.preventDefault();
props.sendSubmission(formSubmission());

setWordFields({
adj1: '',
noun1: '',
adv: '',
verb: '',
adj2: '',
noun2: ''
});
};

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={ onFormSubmit } >

<div className="PlayerSubmissionForm__poem-inputs">

{
// Put your form inputs here... We've put in one below as an example
}
<input
placeholder="hm..."
type="text" />
props.fields.map((field, i) => {

if (typeof field === 'object') {
return(
<input
key={i}
value={wordFields[field.key]}
name={field.key}
placeholder={field.placeholder}
type="text"
onChange={onInputChange}
className={isValid(wordFields[field.key]) ? 'PlayerSubmissionForm__input' : 'PlayerSubmissionForm__input--invalid'}
/>
)
} else {
return(
<span key={i}>
{field}
</span>
)
}
})
}
</div>

<div className="PlayerSubmissionForm__submit">
Expand Down
7 changes: 5 additions & 2 deletions src/components/RecentSubmission.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import React from 'react';
import PropTypes from 'prop-types';
import './RecentSubmission.css';
Expand All @@ -6,7 +7,9 @@ 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 All @@ -15,4 +18,4 @@ RecentSubmission.propTypes = {
submission: PropTypes.string.isRequired,
};

export default RecentSubmission;
export default RecentSubmission;
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