From a7a25bb15cae11d0ee525d9c3a1b456fb536c106 Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Sun, 15 Jan 2017 22:01:22 -0500 Subject: [PATCH] wip #101 --- app/actions/trainer.js | 4 ++-- app/screens/Detail/components/Nickname.js | 2 +- app/screens/Table/components/PokemonRow.js | 15 ------------- .../Table/components/PokemonTableHead.js | 18 ++++++++-------- app/screens/Table/components/Species.js | 21 ++++++++++++++++++- app/utils.js | 2 +- 6 files changed, 33 insertions(+), 29 deletions(-) diff --git a/app/actions/trainer.js b/app/actions/trainer.js index c9048bb..95fbb9d 100644 --- a/app/actions/trainer.js +++ b/app/actions/trainer.js @@ -220,8 +220,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/PokemonRow.js b/app/screens/Table/components/PokemonRow.js index 16cf8c6..681926f 100644 --- a/app/screens/Table/components/PokemonRow.js +++ b/app/screens/Table/components/PokemonRow.js @@ -5,13 +5,6 @@ import { ipcRenderer } from 'electron' import $ from 'jquery' import utils from '../../../utils' -// import { bindActionCreators } from 'redux' -// import { connect } from 'react-redux' -// import { -// toggleFavoritePokemon, -// powerUpPokemon -// } from '../../../actions' - import renderModal from '../../Detail' import Tooltip from '../../Tooltip' @@ -26,18 +19,10 @@ class PokemonRow extends React.PureComponent { static displayName = 'PokemonRow' static propTypes = { - // speciesIndex: PropTypes.number, - // sortBy: PropTypes.string, - // sortDir: PropTypes.string, - // sortPokemonBy: PropTypes.func.isRequired, - // onCheckedChange: PropTypes.func.isRequired, species: PropTypes.object.isRequired, pokemon: PropTypes.object.isRequired, getPokemonState: PropTypes.func.isRequired, onCheckedChange: PropTypes.func.isRequired, - // checkAll: PropTypes.bool.isRequired, - // onCheckAll: PropTypes.func.isRequired, - // getPokemonState: PropTypes.func.isRequired, toggleFavoritePokemon: PropTypes.func.isRequired, powerUpPokemon: PropTypes.func.isRequired, } diff --git a/app/screens/Table/components/PokemonTableHead.js b/app/screens/Table/components/PokemonTableHead.js index 2b1131e..752af1d 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 { speciesIndex, - sortPokemonBy + sortPokemonBy, } = this.props sortPokemonBy(sortBy, speciesIndex) @@ -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 4ae9157..422c5eb 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, i, sortBy, sortDir, collapsed, pokemonState, checkAll) ]) diff --git a/app/utils.js b/app/utils.js index 137b3c3..7e6af4f 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))) {