import React from 'react'; import classNames from 'classnames'; import { CombatMoveStats, ICombatMoveStats, IPokemonMove } from 'app/models/Pokemon'; import { ITypeCoverage } from 'app/types'; import { MovesDropdown } from 'app/components/MovesDropdown'; import { TypeIndicator } from './TypeIndicator'; import * as styles from 'app/styles/MovesExplorer.scss'; export interface IMovesExplorerProps { movesById : CombatMoveStats; quickMoves : Array; chargeMoves : Array; handleToggleDropdownOpen : (isOpen : boolean) => void; handleChangeTypeCoverage : (typeCoverage : ITypeCoverage) => void; } interface IState { quickMove : IPokemonMove | null; chargeMove1 : IPokemonMove | null; chargeMove2 : IPokemonMove | null; } export class MovesExplorer extends React.Component { constructor(props : IMovesExplorerProps) { super(props); this.state = { quickMove: null, chargeMove1: null, chargeMove2: null, }; } public render() { const { movesById, quickMoves, chargeMoves, handleToggleDropdownOpen, } = this.props; const { quickMove, chargeMove1, chargeMove2, } = this.state; const wrapperCss = classNames( 'nes-container', styles.wrapper, ); const quickMoveType = this.getMoveType(quickMove); const chargeMove1Type = this.getMoveType(chargeMove1); const chargeMove2Type = this.getMoveType(chargeMove2); return (
{ quickMove && quickMoveType && } { chargeMove1 && chargeMove1Type && } { chargeMove2 && chargeMove2Type && }
); } private readonly getMoveType = (move : IPokemonMove | null) => { let moveStats : ICombatMoveStats | null = null; if (move !== null) { moveStats = this.props.movesById.get(move.id) || null; } if (moveStats !== null) { return moveStats.type; } return null; } private readonly handleChangeQuickMove = (option : IPokemonMove) => { const { chargeMove1, chargeMove2, } = this.state; this.setState({ quickMove: option, }); this.props.handleChangeTypeCoverage({ type1: this.getMoveType(option), type2: this.getMoveType(chargeMove1), type3: this.getMoveType(chargeMove2), }); } private readonly handleChangeChargeMove1 = (option : IPokemonMove) => { const { quickMove, chargeMove2, } = this.state; this.setState({ chargeMove1: option, }); this.props.handleChangeTypeCoverage({ type1: this.getMoveType(quickMove), type2: this.getMoveType(option), type3: this.getMoveType(chargeMove2), }); } private readonly handleChangeChargeMove2 = (option : IPokemonMove) => { const { quickMove, chargeMove1, } = this.state; this.setState({ chargeMove2: option, }); this.props.handleChangeTypeCoverage({ type1: this.getMoveType(quickMove), type2: this.getMoveType(chargeMove1), type3: this.getMoveType(option), }); } }