import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { loadPlayers, loadParams } from '../../actions/appActions';
import { Avatar, Table } from 'antd';
class Scoreboard extends Component {
constructor(props) {
super(props);
this.state = {
players: [],
playersLoadError: false,
params: []
};
this.loadPlayerInterval = null;
}
componentDidMount() {
this.loadPlayerInterval = setInterval(
() => this.loadPlayers(),
3000
);
};
componentWillUnmount() {
clearInterval(this.loadPlayerInterval);
};
loadPlayers = () => {
let currentShow = this.props.params.find((param) => {
return param.key === 'current show';
});
if (currentShow) {
this.props.loadPlayers(currentShow.value);
}
};
render() {
let orderedPlayers = this.props.players.sort(function (a, b) {
return b.values.score - a.values.score;
});
for (var i = 0; i < orderedPlayers.length; i++) {
orderedPlayers[i].standing = i + 1;
}
const columns = [
{
title: '',
dataIndex: 'standing',
key: 'standing',
width: 50
}, {
title: 'Avatar',
dataIndex: 'playerId',
key: 'playerId',
width: 100,
render: (playerId) => (