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 Maps extends React.Component { constructor(props) { super(props) this.state = { mapTimes: [], mapName: '', breakload: true, scrollListener: {}, fetchsize: 0, }; this.scrollListener = this.handleScroll.bind(this); } componentWillMount = async () => { window.addEventListener('scroll', this.scrollListener); this.setState({ breakload: false }) const mapname = this.props.match.params.mapname; const stage = this.props.match.params.stage; try { const mapTimes = await Facade.getMapTimesFromCache(mapname, stage, 0); const fetchsize = await Facade.getMapTimesFromCacheSize(mapname, stage); this.setState({ mapTimes }); this.setState({ fetchsize }); } catch (error) { console.log("invalid map or stage"); } this.setState({ mapName: mapname }) this.setState({ breakload: true }) }; componentWillUnmount() { window.removeEventListener("scroll", this.scrollListener); } findLateIndex(array) { return array[array.length - 5]; } handleScroll = () => { if (this.state.breakload && this.state.fetchsize > this.state.mapTimes.length) { const player = this.findLateIndex(this.state.mapTimes); var lastLi = document.getElementById('maps/' + player.steamID); var lastLiOffset = lastLi.offsetTop + lastLi.clientHeight; var pageOffset = window.pageYOffset + window.innerHeight; if (pageOffset > lastLiOffset) { this.setState({ breakload: false }) this.loadPlayers(); } } }; loadPlayers = async () => { const mapname = this.props.match.params.mapname; const stage = this.props.match.params.stage; const mapTimes = await Facade.getMapTimesFromCache(mapname, stage, this.state.mapTimes.length); this.setState({ mapTimes }); this.setState({ breakload: true }) } render() { return (

Map: {this.state.mapName}

Stage: {this.props.match.params.stage}

MapBoard

LeaderBoard

{this.state.mapTimes.map(e => (
SteamID: {e.steamID}
Name: {e.name}

Position: {e.position}
Mappoints: {e.mapPoint}
Time: {e.mapTime}
{Object.keys(e.badgesUrls).map(badges => (

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

: this.state.fetchsize === 0 ?

No data found

: ""}
) } } export default Maps;