Skip to content

Commit

Permalink
wip #101
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnymac committed Jan 16, 2017
1 parent e64a65d commit a7a25bb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/actions/trainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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
15 changes: 0 additions & 15 deletions app/screens/Table/components/PokemonRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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,
}
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 {
speciesIndex,
sortPokemonBy
sortPokemonBy,
} = this.props

sortPokemonBy(sortBy, speciesIndex)
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, i, 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 a7a25bb

Please sign in to comment.