From 48718c51deb682aa7983ba4b363d81a93eda22a5 Mon Sep 17 00:00:00 2001 From: Jeff Colombo Date: Sat, 19 Jan 2019 21:20:18 -0500 Subject: [PATCH] show rank info --- src/ts/app/PokemonApp.tsx | 4 + .../PokemonExplorer/PokemonExplorer.tsx | 87 ++++++++++++++++--- 2 files changed, 77 insertions(+), 14 deletions(-) diff --git a/src/ts/app/PokemonApp.tsx b/src/ts/app/PokemonApp.tsx index 83616c9..b50014b 100644 --- a/src/ts/app/PokemonApp.tsx +++ b/src/ts/app/PokemonApp.tsx @@ -65,6 +65,10 @@ class PokemonApp extends React.Component { dispatch(ActionsPokemonSelectList.fetchPokemonLeagueStats(pokemonId)) .then((leaguePokemon) => { dispatch(ActionsPokemonSelectList.setActivePokemonIndex(pokemonIndex)); + dispatch(ActionsPokemonExplorer.setIvLevel(null)); + dispatch(ActionsPokemonExplorer.setIvHp(null)); + dispatch(ActionsPokemonExplorer.setIvAtk(null)); + dispatch(ActionsPokemonExplorer.setIvDef(null)); dispatch(ActionsPokemonExplorer.setLeaguePokemon(leaguePokemon)); }) .catch((error) => { diff --git a/src/ts/app/components/PokemonExplorer/PokemonExplorer.tsx b/src/ts/app/components/PokemonExplorer/PokemonExplorer.tsx index a0eb401..96c7fc1 100644 --- a/src/ts/app/components/PokemonExplorer/PokemonExplorer.tsx +++ b/src/ts/app/components/PokemonExplorer/PokemonExplorer.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import { ILeaguePokemon } from 'app/models/Pokemon'; +import { Grade, ILeaguePokemon, IStats } from 'app/models/Pokemon'; import { IIndividualValues, IndividualValueKey } from './types'; @@ -13,6 +13,9 @@ export interface IPokemonExplorerProps { } interface IState { + form : { + level : string; + }; } export class PokemonExplorer extends React.Component { @@ -28,6 +31,12 @@ export class PokemonExplorer extends React.Component { + if (individualValueLevel === stats.level && + individualValues.hp === stats.ivHp && + individualValues.atk === stats.ivAtk && + individualValues.def === stats.ivDef + ) { + rankedPokemon = stats; + return true; + } + return false; + }); + + // we don't have the data for this terrible mon + if (rankedPokemon === null) { + rankedPokemon = leaguePokemon.pvp[league][leaguePokemon.pvp[league].length - 1]; + } + } + + const rankedGrade = rankedPokemon !== null ? Grade[rankedPokemon.speciesGrade] : '-'; + const rankedCp = rankedPokemon !== null ? rankedPokemon.cp : '-'; + const rankedHp = rankedPokemon !== null ? rankedPokemon.hp : '-'; + const rankedAtk = rankedPokemon !== null ? rankedPokemon.atk : '-'; + const rankedDef = rankedPokemon !== null ? rankedPokemon.def : '-'; return (
@@ -66,9 +121,9 @@ export class PokemonExplorer extends React.Component
@@ -113,11 +168,11 @@ export class PokemonExplorer extends React.Component
-
{ } Rank
-
CP { }
-
{ } HP
-
{ } ATK
-
{ } DEF
+
{ rankedGrade } Rank
+
CP { rankedCp }
+
{ rankedHp } HP
+
{ rankedAtk } ATK
+
{ rankedDef } DEF
); @@ -136,11 +191,15 @@ export class PokemonExplorer extends React.Component) => { const raw = event.currentTarget.value; - const value = parseInt(raw, 10); - if (raw === '' + value && value >= this.MIN_LEVEL && value <= this.MAX_LEVEL) { + const value = parseFloat(raw); + + this.setState({ form: { level: '' } }); + if (raw === '' + value && value >= this.MIN_LEVEL && value <= this.MAX_LEVEL && value % 0.5 === 0) { this.props.handleChangeIndividualValue('level', value); } else if (raw === '') { this.props.handleChangeIndividualValue('level', null); + } else if (raw.charAt(raw.length) === '.') { + this.setState({ form: { level: raw } }); } }