diff --git a/src/components/app.tsx b/src/components/app.tsx index 6a70d73..bd6a68e 100644 --- a/src/components/app.tsx +++ b/src/components/app.tsx @@ -31,6 +31,7 @@ export default class Application extends React.Component<{}, IState> { } lessons(): ILesson[] { + // TODO: Actually fetch them from somewhere const lessons = [{ name: "Der Bauer auf dem Feld", desc: "So fängt alles an: Du bist ein einfacher Bauer und musst dich die Karriereleiter mit deinen freshen Latein-Skills hinaufarbeiten", @@ -46,6 +47,22 @@ export default class Application extends React.Component<{}, IState> { return lessons; } + learners(): ILearner[] { + return [{ + username: "Polynomdivision", + level: 5, + score: 400, + }, { + username: "Polynomdivision2", + level: 3, + score: 500, + }, { + username: "Der eine Typ", + level: 7, + score: 100, + }]; + } + login(username: string, password: string): Promise { return new Promise((res, rej) => { // TODO @@ -79,8 +96,14 @@ export default class Application extends React.Component<{}, IState> { { return }} /> - } /> - } /> + } /> + } /> ; diff --git a/src/components/scoreboard.tsx b/src/components/scoreboard.tsx new file mode 100644 index 0000000..58b8c09 --- /dev/null +++ b/src/components/scoreboard.tsx @@ -0,0 +1,73 @@ +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 { ILearner } from "../models/learner"; + +interface IProps { + learners: ILearner[]; +} + +export default class Scoreboard extends React.Component<{}> { + private unique = 0; + private nr = 1; + + constructor(props: any) { + super(props); + + this.genId = this.genId.bind(this); + this.tableRow = this.tableRow.bind(this); + } + + genId() { + return "SCOREBOARD" + this.unique++; + } + + tableRow(learner: ILearner) { + return + + + {this.nr++} + + + + {learner.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.learners.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)} + +
; + } +} diff --git a/src/models/learner.ts b/src/models/learner.ts new file mode 100644 index 0000000..1eed05e --- /dev/null +++ b/src/models/learner.ts @@ -0,0 +1,5 @@ +export interface ILearner { + username: string; + level: number; + score: number; +} diff --git a/src/pages/dashboard.tsx b/src/pages/dashboard.tsx index 290c166..c4ebc45 100644 --- a/src/pages/dashboard.tsx +++ b/src/pages/dashboard.tsx @@ -3,50 +3,43 @@ import * as React from "react"; import Grid from "@material-ui/core/Grid"; import Typography from "@material-ui/core/Typography"; import Button from "@material-ui/core/Button"; -import Card from '@material-ui/core/Card'; -import CardActions from '@material-ui/core/CardActions'; -import CardContent from '@material-ui/core/CardContent'; +import Paper from "@material-ui/core/Paper"; + +import Scoreboard from "../components/scoreboard"; import { ILesson } from "../models/lesson"; +import { ILearner } from "../models/learner"; interface IProps { lessons: ILesson[]; + learners: ILearner[]; } export default class Dashboard extends React.Component<{}> { - constructor(props: any) { - super(props); - } - render() { const small = window.matchMedia("(max-width: 700px)").matches; - const cName = small ? "lesson-card-xs" : "lesson-card-lg"; + const direction = small ? "column" : "row"; - let key = 0; - const lessonToCard = (lesson: ILesson) => { - return - - - {`Level ${lesson.level}`} - {lesson.name} -
- - {lesson.desc} - -
- - - -
-
; - }; + return + + + Nächstes Level + + + + + + Rangliste + - return - {this.props.lessons.map(lessonToCard)} - + + + + + + Some stuff + + + ; } };