/** * DEPRECATED */ import React from 'react'; import { axios } from '../../services'; import * as _ from 'lodash'; import './Pubg.scss'; interface Props {} interface State { players: Player[]; selectedRegion: string; selectedMatch: string; statList: string[]; } interface Player { PlayerName: string; agg?: any; as?: any; na?: any; sa?: any; } export class Pubg extends React.Component { constructor(props: Props) { super(props); this.state = { players: [], selectedRegion: 'agg', selectedMatch: 'squad', statList: [], }; } componentDidMount() { axios.get('/api/stats/pubg').then(res => { this.setState({ players: _.map(res.data) as any, }); this.setStatList(); }); } // get stat list setStatList() { // hacky way to find existing content -- to tired to make it pretty let i = 0; let stats; while (!stats) { if (i > this.state.players.length) { return; } stats = _.find( _.get(this.state, `players[${i}].Stats`), (s: any) => s.Match === this.state.selectedMatch.toLowerCase(), ); i++; } if (stats) { this.setState({ statList: _.sortBy(_.map(stats.Stats, 'field')) as any, }); } } insertRows(): any { return this.state.statList.map((val: any, index: any) => { return ( {val} {this.state.players.map((player: any, i: number) => { // find player stats for field let playerStat = _.find(player.Stats, (p: any) => { return ( p.Match === this.state.selectedMatch.toLowerCase() && p.Region === this.state.selectedRegion.toLowerCase() ); }); return ( {_.get(_.find(_.get(playerStat, 'Stats'), (p: any) => p.field === val), 'displayValue')} ); })} ); }); } buttonRegion(title: string) { let lowerTitle = title === 'All' ? 'agg' : title.toLowerCase(); return ( ); } buttonMatch(title: string) { let lowerTitle = title.toLowerCase(); return ( ); } render() { return (
PUBG Stats
{this.buttonMatch('Solo')} {this.buttonMatch('Duo')} {this.buttonMatch('Squad')}
{this.buttonRegion('All')} {this.buttonRegion('Na')} {this.buttonRegion('As')} {this.buttonRegion('Au')}
; })} {this.insertRows()}
{this.state.players.map((val: any, index: number) => { return {val.PlayerName}
); } }