This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.
Lateinicus/src/pages/dashboard.tsx

82 lines
2.5 KiB
TypeScript
Raw Normal View History

2018-08-26 14:23:48 +00:00
import * as React from "react";
2018-09-06 18:05:21 +00:00
import { Redirect } from "react-router";
2018-08-26 14:23:48 +00:00
import Grid from "@material-ui/core/Grid";
import Typography from "@material-ui/core/Typography";
import Button from "@material-ui/core/Button";
2018-08-26 15:12:07 +00:00
import Paper from "@material-ui/core/Paper";
import Scoreboard from "../components/scoreboard";
2018-08-26 14:23:48 +00:00
2018-09-06 18:13:29 +00:00
import { ILevel } from "../models/level";
2018-08-26 15:12:07 +00:00
import { ILearner } from "../models/learner";
2018-08-26 14:23:48 +00:00
interface IProps {
2018-09-06 18:13:29 +00:00
nextLevel: () => ILevel;
2018-08-26 15:12:07 +00:00
learners: ILearner[];
2018-08-26 14:23:48 +00:00
}
2018-09-06 18:05:21 +00:00
interface IState {
toLevel: number;
}
export default class Dashboard extends React.Component<IProps, IState> {
constructor(props: any) {
super(props);
this.state = {
toLevel: -1;
};
}
2018-08-26 14:23:48 +00:00
render() {
const small = window.matchMedia("(max-width: 700px)").matches;
2018-08-26 15:12:07 +00:00
const direction = small ? "column" : "row";
2018-08-26 14:23:48 +00:00
2018-09-06 18:13:29 +00:00
const level = this.props.nextLevel();
2018-09-06 18:05:21 +00:00
return <div>
{
this.state.toLevel !== -1 ? (
<Redirect to={`/level/${this.state.toLevel}`} />
) : undefined
}
<Grid container direction={direction} spacing={16}>
<Grid item lg={4}>
<Paper className="paper">
2018-09-06 18:13:29 +00:00
<Typography variant="title">{`Level ${level.level}`}</Typography>
<Typography variant="title" component="p">{level.name}</Typography>
2018-09-06 18:05:21 +00:00
<br />
<Typography component="p">
2018-09-06 18:13:29 +00:00
{level.desc}
2018-09-06 18:05:21 +00:00
</Typography>
<Button className="lesson-card-btn"
onClick={() => {
this.setState({
2018-09-06 18:13:29 +00:00
toLevel: level.level,
2018-09-06 18:05:21 +00:00
});
}}>
Zum Level
</Button>
</Paper>
</Grid>
<Grid item lg={4}>
<Paper className="paper">
<Typography variant="title" component="p">
Rangliste: Top 10
2018-08-26 15:12:07 +00:00
</Typography>
2018-08-26 14:23:48 +00:00
2018-09-06 18:05:21 +00:00
<Scoreboard learners={this.props.learners.slice(0, 10)} />
</Paper>
</Grid>
<Grid item lg={4}>
<Paper className="paper">
Some stuff
2018-08-26 15:12:07 +00:00
</Paper>
2018-09-06 18:05:21 +00:00
</Grid>
2018-08-26 15:12:07 +00:00
</Grid>
2018-09-06 18:05:21 +00:00
</div>;
2018-08-26 14:23:48 +00:00
}
};