Skip to content

Commit

Permalink
deliver #101 add extra candy needed span
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnymac committed Jan 17, 2017
1 parent 963e8c6 commit 47255f9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/actions/trainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ function parseInventory(inventory) {
// TODO use map
speciesList.forEach((s) => {
const pokemonSetting = pokemonSettings[s.pokemon_id - 1]
const candyToEvolve = pokemonSetting ? pokemonSetting.candy_to_evolve : 0
s.evolves = utils.getEvolvesCount(candyToEvolve, s)
s.candyToEvolve = pokemonSetting ? pokemonSetting.candy_to_evolve : 0
s.evolves = utils.getEvolvesCount(s.candyToEvolve, s.candy, s.count)
})

return {
Expand Down
2 changes: 1 addition & 1 deletion app/screens/Detail/components/Nickname.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Nickname extends React.Component {
render() {
const {
editing,
newNickname
newNickname,
} = this.state

if (editing) {
Expand Down
18 changes: 9 additions & 9 deletions app/screens/Table/components/PokemonTableHead.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PokemonTableHead extends React.PureComponent {
colSpan="1"
aria-controls="pokemon-data"
aria-label="Favorite: activate to sort column ascending"
onClick={this.handleSortPokemon.bind(this, 'favorite')}
onClick={this.createHandleSortPokemon('favorite')}
>
<span className="fa fa-star favorite-yellow" />
</th>
Expand All @@ -53,7 +53,7 @@ class PokemonTableHead extends React.PureComponent {
colSpan="1"
aria-controls="pokemon-data"
aria-label="Name: activate to sort column ascending"
onClick={this.handleSortPokemon.bind(this, 'name')}
onClick={this.createHandleSortPokemon('name')}
>
Name
</th>
Expand All @@ -64,7 +64,7 @@ class PokemonTableHead extends React.PureComponent {
colSpan="1"
aria-controls="pokemon-data"
aria-label="Nickname: activate to sort column ascending"
onClick={this.handleSortPokemon.bind(this, 'nickname')}
onClick={this.createHandleSortPokemon('nickname')}
>
Nickname
</th>
Expand All @@ -75,7 +75,7 @@ class PokemonTableHead extends React.PureComponent {
colSpan="1"
aria-controls="pokemon-data"
aria-label="CP: activate to sort column ascending"
onClick={this.handleSortPokemon.bind(this, 'cp')}
onClick={this.createHandleSortPokemon('cp')}
>
CP
</th>
Expand All @@ -86,7 +86,7 @@ class PokemonTableHead extends React.PureComponent {
colSpan="1"
aria-controls="pokemon-data"
aria-label="Level: activate to sort column ascending"
onClick={this.handleSortPokemon.bind(this, 'level')}
onClick={this.createHandleSortPokemon('level')}
>
Level
</th>
Expand All @@ -97,7 +97,7 @@ class PokemonTableHead extends React.PureComponent {
colSpan="1"
aria-controls="pokemon-data"
aria-label="IV: activate to sort column ascending"
onClick={this.handleSortPokemon.bind(this, 'iv')}
onClick={this.createHandleSortPokemon('iv')}
>
IV
</th>
Expand All @@ -115,10 +115,10 @@ class PokemonTableHead extends React.PureComponent {
onCheckAll(species)
}

handleSortPokemon = (sortBy) => {
createHandleSortPokemon = (sortBy) => () => {
const {
pokemonId,
sortPokemonBy
sortPokemonBy,
} = this.props

sortPokemonBy(sortBy, pokemonId - 1)
Expand All @@ -127,7 +127,7 @@ class PokemonTableHead extends React.PureComponent {
getSortDirectionClassName = (key) => {
const {
sortBy,
sortDir
sortDir,
} = this.props

if (sortBy === key) {
Expand Down
21 changes: 20 additions & 1 deletion app/screens/Table/components/Species.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ class Species extends React.Component {
sortDir
} = speciesState[specie.pokemon_id]

let extraCandyNeededSpan

if (specie.evolves > 0) {
const totalCandyNeeded = specie.candyToEvolve * specie.count
const extraCandyNeeded = totalCandyNeeded - specie.candy
if (extraCandyNeeded > 0) {
extraCandyNeededSpan = (
<span>
{` +${extraCandyNeeded}`}
</span>
)
}
}

return ([
<tr
className={collapsed ? '' : 'shown'}
Expand All @@ -161,7 +175,12 @@ class Species extends React.Component {
</td>
<td>{specie.name}</td>
<td>{specie.count}</td>
<td>{specie.candy}</td>
<td>
<span>
{specie.candy}
</span>
{extraCandyNeededSpan}
</td>
<td>{specie.evolves}</td>
</tr>, this.getPokemonTable(specie, sortBy, sortDir, collapsed, pokemonState, checkAll)
])
Expand Down
2 changes: 1 addition & 1 deletion app/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ const utils = {
return Math.round(utils.getADS(pokemon) / 45 * 10000) / 100
},

getEvolvesCount(evolveCost, { candy, count }) {
getEvolvesCount(evolveCost, candy, count) {
let evolves = Math.floor(candy / evolveCost)

if ((evolves === Infinity || isNaN(evolves))) {
Expand Down

0 comments on commit 47255f9

Please sign in to comment.