forked from AdaGold/litter-patrol
-
Notifications
You must be signed in to change notification settings - Fork 45
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
Katherine Litter Patrol #45
Open
KatherineJF
wants to merge
3
commits into
Ada-C10:master
Choose a base branch
from
KatherineJF:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import React, { Component } from 'react'; | |
import uuid from 'uuid'; | ||
import './App.css'; | ||
import GameItem from './components/GameItem.js'; | ||
import ItemIcons from './ItemIcons.js'; | ||
import logo from './images/logo.png'; | ||
|
||
class App extends Component { | ||
|
@@ -39,15 +40,19 @@ class App extends Component { | |
console.log(this.state); | ||
} | ||
|
||
onItemClicked = () => { | ||
// Fill this in! | ||
handleItemClick = (itemType) => {//scoring based on item type clicked | ||
if (itemType === 'litter') { | ||
this.setState({ points: this.state.points + 1 }); | ||
} | ||
} | ||
|
||
render() { | ||
const items = this.state.items.map((item, i) => { | ||
return <GameItem | ||
height={item.height} // Height - used for a CSS style to position on the screen | ||
layer={100 + i} // Layer - used for a CSS style to show items on-top of bg | ||
layer={100 + i} | ||
itemType={item.type} //prop for GameItem | ||
onItemClick={this.handleItemClick}// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be a good idea to name this with the term callback, just for readability. |
||
key={item.id} // Key - to help React with performance | ||
|
||
// Additional props (event callbacks, etc.) can be passed here | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,55 @@ | ||
//3rd party apps first | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import '../App.css'; | ||
import ItemIcons from '../ItemIcons.js'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class GameItem extends Component { | ||
|
||
//always send constructor and super props | ||
constructor(props) { | ||
super(props); | ||
//this is how you declare state on a variable, key = variable and value = empty string per PropTypes | ||
this.state = { //state is managed by child | ||
itemClass: '' //setting state for .css class selected | ||
}; | ||
} | ||
//variable set to booleen - if prop type is litter select class litter else nature | ||
handleItemClick = () => { | ||
const itemClickedClass = (this.props.itemType === 'litter') | ||
? 'spotted-litter' | ||
: 'spotted-nature'; | ||
this.setState({ itemClass: itemClickedClass }); // if varaible name same as state then just {itemClass} | ||
|
||
//callback to app.js | ||
if (this.props.onItemClick) {//onItemClick passed as prop to GameItem | ||
this.props.onItemClick(this.props.itemType);//passing itemType prop to app.js | ||
} | ||
} | ||
|
||
render() { | ||
const itemStyle = { | ||
bottom: `${this.props.height}px`, // use props.height to offset from the bottom of screen | ||
zIndex: this.props.layer, // use props.layer to set z-index, so we display ontop of background | ||
}; | ||
|
||
// Update this to select the correct icon for each item | ||
const icon = ItemIcons.rock; | ||
//Update this to select the correct icon for each item | ||
//const icon = ItemIcons.rock; | ||
const icon = ItemIcons[this.props.itemType]; //imported itemIcons key/value ItemIcons by prop type | ||
|
||
return ( | ||
<div className="game-item" style={itemStyle}> | ||
<div | ||
className={`game-item ${this.state.itemClass}`} //gave the class two .css styles | ||
style={itemStyle} //itemClass is the state litter or nature .css | ||
onClick={this.handleItemClick} //function defined above render | ||
> | ||
<img src={icon} alt="Item" className="icon-item"></img> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
|
||
GameItem.propTypes = { | ||
GameItem.propTypes = { //props come from parent | ||
itemType: PropTypes.string.isRequired, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't the callback be included here |
||
height: PropTypes.number.isRequired, | ||
layer: PropTypes.number.isRequired, | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't seem to be using this here.