import * as React from "react"; import Table from "@material-ui/core/Table"; import TableHead from "@material-ui/core/TableHead"; import TableBody from "@material-ui/core/TableBody"; import TableRow from "@material-ui/core/TableRow"; import TableCell from "@material-ui/core/TableCell"; import Typography from "@material-ui/core/Typography"; import { TopTen } from "../models/learner"; interface IProps { topTen: TopTen[]; } export default class Scoreboard extends React.Component { private unique = 0; constructor(props: any) { super(props); this.genId = this.genId.bind(this); this.tableRow = this.tableRow.bind(this); } genId() { return "SCOREBOARD" + this.unique++; } tableRow(learner: TopTen) { // Gotta show respect! (That Unicode monster is a crown) const username = { false: learner.username, true: `${learner.username} 👑` }[learner.nr === 1]; return {learner.nr} {username} {/*{learner.level}*/} {/* To make this fit on both mobile and desktop, we don't use numeric, as it would otherwise look weir otherwise look weird */} {learner.score} } render() { const sortedLearners = this.props.topTen.sort((a, b) => { if (a.score > b.score) { return -1; } else if (a.score < b.score) { return 1; } return 0; }); return # User {/*Level*/} Punktzahl {sortedLearners.map(this.tableRow)}
; } }