From 47255f9fee68918fe2929d56caa944aa76448c0d Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Sun, 15 Jan 2017 22:01:22 -0500 Subject: [PATCH] deliver #101 add extra candy needed span --- app/actions/trainer.js | 4 ++-- app/screens/Detail/components/Nickname.js | 2 +- .../Table/components/PokemonTableHead.js | 18 ++++++++-------- app/screens/Table/components/Species.js | 21 ++++++++++++++++++- app/utils.js | 2 +- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/app/actions/trainer.js b/app/actions/trainer.js index 65d0fe8..8bb7579 100644 --- a/app/actions/trainer.js +++ b/app/actions/trainer.js @@ -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 { diff --git a/app/screens/Detail/components/Nickname.js b/app/screens/Detail/components/Nickname.js index 8703d4d..9602e78 100644 --- a/app/screens/Detail/components/Nickname.js +++ b/app/screens/Detail/components/Nickname.js @@ -64,7 +64,7 @@ class Nickname extends React.Component { render() { const { editing, - newNickname + newNickname, } = this.state if (editing) { diff --git a/app/screens/Table/components/PokemonTableHead.js b/app/screens/Table/components/PokemonTableHead.js index 23d2d22..eaf1feb 100644 --- a/app/screens/Table/components/PokemonTableHead.js +++ b/app/screens/Table/components/PokemonTableHead.js @@ -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')} > @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -127,7 +127,7 @@ class PokemonTableHead extends React.PureComponent { getSortDirectionClassName = (key) => { const { sortBy, - sortDir + sortDir, } = this.props if (sortBy === key) { diff --git a/app/screens/Table/components/Species.js b/app/screens/Table/components/Species.js index 5684d7c..df97b76 100644 --- a/app/screens/Table/components/Species.js +++ b/app/screens/Table/components/Species.js @@ -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 = ( + + {` +${extraCandyNeeded}`} + + ) + } + } + return ([ {specie.name} {specie.count} - {specie.candy} + + + {specie.candy} + + {extraCandyNeededSpan} + {specie.evolves} , this.getPokemonTable(specie, sortBy, sortDir, collapsed, pokemonState, checkAll) ]) diff --git a/app/utils.js b/app/utils.js index d5dd4c1..f5bcbfd 100644 --- a/app/utils.js +++ b/app/utils.js @@ -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))) {