Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
40b51de
add inputs and event listeners
seaweeddol Apr 22, 2020
f884f20
add state, callback function, and send props to components
seaweeddol Apr 22, 2020
2713bb3
display recent submission via props
seaweeddol Apr 22, 2020
bd77365
change prop name form currentSubmission to recentSubmission
seaweeddol Apr 22, 2020
fd2ef80
fix capitalization on props.recentSubmission
seaweeddol Apr 22, 2020
1bcc0b3
fix reference to noun1
seaweeddol Apr 22, 2020
899edae
add finalPoem state and update player and finalPoem on callback
seaweeddol Apr 22, 2020
e6ab498
remove wave 1 comments
seaweeddol Apr 22, 2020
356952c
change structure of Game to keep track of all submissions as objects
seaweeddol Apr 22, 2020
09cc277
loop through submissions and add to an array
seaweeddol Apr 22, 2020
9ddbaa6
change FinalPoem props name from finalPoem to submissions
seaweeddol Apr 22, 2020
792ca3c
map sentences to finalPoem variable to display
seaweeddol Apr 22, 2020
edc29f4
add logic to show final poem with each sentence on new line when butt…
seaweeddol Apr 22, 2020
c7638ed
change callback structure to add string instead of object to submissi…
seaweeddol Apr 22, 2020
252990d
update to use submission strings from Game
seaweeddol Apr 22, 2020
dadbbd4
add logic to hide RecentSubmission component unless there is a submis…
seaweeddol Apr 22, 2020
437aa9a
add submitted state to Game component; update nested components to di…
seaweeddol Apr 23, 2020
550343a
remove display state and add callback function to change submitted st…
seaweeddol Apr 23, 2020
d239923
add input validation for blank fields
seaweeddol Apr 23, 2020
8028997
pass FIELDS to PlayerSubmissionForm
seaweeddol Apr 23, 2020
29a9ca4
refactor PlayerSubmissionForm to dynamically generate the input fields
seaweeddol Apr 23, 2020
6bc71c8
cleanup code & add PropTypes
seaweeddol Apr 23, 2020
2a234cb
modify package.json to allow github page publishing
seaweeddol Apr 23, 2020
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
91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"name": "exquisite-react",
"version": "0.1.0",
"private": true,
"homepage": "https://seaweeddol.github.io/exquisite-react/",
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"gh-pages": "^2.2.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
Expand All @@ -14,6 +16,8 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"eject": "react-scripts eject"
},
"eslintConfig": {
Expand Down
38 changes: 31 additions & 7 deletions src/components/FinalPoem.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
import React from 'react';
import PropTypes from 'prop-types';
import './FinalPoem.css';

const FinalPoem = (props) => {

let increment = 0;
let finalPoem = props.submissions.map(sentence => {
increment += 1
return (<p key={increment}>{sentence}</p>)
});

const onReveal = () => {
props.onFinalPoemCallback(true);
}

return (
<div className="FinalPoem">
<section className="FinalPoem__poem">
<h3>Final Poem</h3>

</section>
{/* if display is true, show final poem */}
{ props.submitted ?
<section className="FinalPoem__poem">
<h3>Final Poem</h3>
{finalPoem}
</section> :
null
}

<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" />
</div>
{ props.submitted ?
null :
<div className="FinalPoem__reveal-btn-container">
<input type="button" value="We are finished: Reveal the Poem" className="FinalPoem__reveal-btn" onClick={onReveal}/>
</div>
}
</div>
);
}

FinalPoem.propTypes = {
submissions: PropTypes.arrayOf(PropTypes.string),
submitted: PropTypes.bool.isRequired,
onFinalPoemCallback: PropTypes.func,
}

export default FinalPoem;
4 changes: 4 additions & 0 deletions src/components/Game.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
text-align: center;
font-style: italic;
}

.hide {
display: none;
}
47 changes: 39 additions & 8 deletions src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ const Game = () => {
}
}).join(" ");

const [player, setPlayer] = useState(1);
const [submissionsList, setsubmissionsList] = useState([]);
const [submitted, setSubmitted] = useState(false);


const onPlayerSubmissionCallback = (playerSubmission) => {
// make a copy of submissionsList
const newSubmissions = [...submissionsList];

// create sentence structure
const sentence = "The " + playerSubmission.adjective1 + " " + playerSubmission.noun1 + " " + playerSubmission.adverb + " " + playerSubmission.verb + " the " + playerSubmission.adjective2 + " " + playerSubmission.noun2 + ".";

newSubmissions.push(sentence);
// update state of submissionsList to new list
setsubmissionsList(newSubmissions);
// increment player
setPlayer(player + 1);
}

const onFinalPoemCallback = (bool) => {
setSubmitted(bool);
}

// on reset
// setPlayer(1)

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

<RecentSubmission />
<section className={submitted ? 'hide' : 'show'}>
{
submissionsList.length > 0 ?
<RecentSubmission recentSubmission={submissionsList[submissionsList.length - 1]}/> :
null
}

<PlayerSubmissionForm player={player} onSubmit={onPlayerSubmissionCallback} fields={FIELDS} />
</section>

<PlayerSubmissionForm />

<FinalPoem />
<FinalPoem submissions={submissionsList} submitted={submitted} onFinalPoemCallback={onFinalPoemCallback}/>

</div>
);
}


const FIELDS = [
"The",
{
key: 'adj1',
key: 'adjective1',
placeholder: 'adjective',
},
{
key: 'noun1',
placeholder: 'noun',
},
{
key: 'adv',
key: 'adverb',
placeholder: 'adverb',
},
{
Expand All @@ -56,7 +87,7 @@ const FIELDS = [
},
"the",
{
key: 'adj2',
key: 'adjective2',
placeholder: 'adjective',
},
{
Expand Down
Loading