-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Katz
authored and
David Katz
committed
Jun 17, 2017
1 parent
805fa5e
commit 1e59001
Showing
9 changed files
with
148 additions
and
7 deletions.
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
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,9 +1,18 @@ | ||
export const ADD_CHARACTER = 'ADD_CHARACTER'; | ||
export const REMOVE_CHARACTER = 'REMOVE_CHARACTER'; | ||
|
||
export function addCharacterById(id) { | ||
const action = { | ||
type: ADD_CHARACTER, | ||
id | ||
} | ||
return action; | ||
} | ||
|
||
export function removeCharacterById(id) { | ||
const action = { | ||
type: REMOVE_CHARACTER, | ||
id | ||
} | ||
return action; | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { removeCharacterById } from '../actions'; | ||
|
||
class HeroList extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<h4>Your Hero Squad</h4> | ||
<ul className="list-group"> | ||
{ | ||
this.props.heroes.map(hero => { | ||
return ( | ||
<li key={hero.id} className="list-group-item"> | ||
<div className="list-item"> | ||
{hero.name} | ||
</div> | ||
<div | ||
className="list-item right-button" | ||
onClick={() => this.props.removeCharacterById(hero.id)} | ||
> | ||
x | ||
</div> | ||
</li> | ||
) | ||
}) | ||
} | ||
</ul> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
heroes: state.heroes | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps, { removeCharacterById })(HeroList); |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
|
||
class SquadStats extends Component { | ||
strength() { | ||
let strength = 0; | ||
this.props.heroes.forEach(hero => strength += hero.strength); | ||
return strength; | ||
} | ||
|
||
intelligence() { | ||
let intelligence = 0; | ||
this.props.heroes.forEach(hero => intelligence += hero.intelligence); | ||
return intelligence; | ||
} | ||
|
||
speed() { | ||
let speed = 0; | ||
this.props.heroes.forEach(hero => speed += hero.speed); | ||
return speed; | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<h4>Squad Stats</h4> | ||
<ul className="list-group"> | ||
<li className="list-group-item"> | ||
<b>Overall Strength:</b> {this.strength()} | ||
</li> | ||
<li className="list-group-item"> | ||
<b>Overall Intelligence:</b> {this.intelligence()} | ||
</li> | ||
<li className="list-group-item"> | ||
<b>Overall Speed:</b> {this.speed()} | ||
</li> | ||
</ul> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
heroes: state.heroes | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps, null)(SquadStats); |
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
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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
body { | ||
background-image: url('../assets/background.jpg'); | ||
height: 100%; | ||
background-size: cover; | ||
background-repeat: none; | ||
opacity: 0.8; | ||
} | ||
|
||
.App { | ||
text-align: center; | ||
padding: 5%; | ||
} | ||
|
||
.right-button { | ||
cursor: pointer; | ||
float: right; | ||
} | ||
|
||
.list-item { | ||
display: inline-block; | ||
} |