import React from 'react'; import Facade from '../Datafacade/datafacade'; import { NavLink } from 'react-router-dom'; import Loader from 'react-loader-spinner'; import { usePromiseTracker } from "react-promise-tracker"; import '../css/style.css'; const LoadingIndicator = props => { const { promiseInProgress } = usePromiseTracker(); return promiseInProgress &&
}; class Player extends React.Component { constructor(props) { super(props) this.state = { player: {}, mapTimes: [], breakload: true, scrollListener: {}, }; this.scrollListener = this.handleScroll.bind(this); } componentWillMount = async () => { window.addEventListener('scroll', this.scrollListener); this.setState({ breakload: false }) const steamid = this.props.match.params.steamid; const player = await Facade.getPlayerFromCache(steamid); const mapTimes = await Facade.getPlayerTimesFromCache(steamid, 0); this.setState({ player }); this.setState({ mapTimes }); this.setState({ breakload: true }) }; componentWillUnmount() { window.removeEventListener("scroll", this.scrollListener); } findSecondLast(array) { return array[array.length - 2]; } handleScroll = () => { if (this.state.breakload && this.state.player.Times > this.state.mapTimes.length) { const map = this.findSecondLast(this.state.mapTimes); var lastLi = document.getElementById("playermaps/" + map.mapname + "/" + map.mapstage); var lastLiOffset = lastLi.offsetTop + lastLi.clientHeight; var pageOffset = window.pageYOffset + window.innerHeight; if (pageOffset > lastLiOffset) { this.setState({ breakload: false }) this.loadMaps(); } } }; loadMaps = async () => { const steamid = this.props.match.params.steamid; const mapTimes = await Facade.getPlayerTimesFromCache(steamid, this.state.mapTimes.length + 1); this.setState({ mapTimes }); this.setState({ breakload: true }) } render() { return (

leaderboard

MapBoard

{this.state.player.steamID}
{this.state.player.name}

Rank: {this.state.player.Rank}
Points: {this.state.player.PlayerPoints}
Times: {this.state.player.Times}


{this.state.mapTimes.map(e => (
  • Map: {e.mapname}
    Stage: {e.mapstage}
    Position: {e.position}
    Time: 0{e.mapTimeMinutes}:{e.mapTimeSeconds}
    MapPoints: {e.mapPoint}


  • ))} {!this.state.breakload ?

    Loading Stats

    : ""}
    ); } } export default Player;