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/frontend/src/pages/levelList.tsx

91 lines
3.0 KiB
TypeScript
Raw Normal View History

2018-08-26 14:23:48 +00:00
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';
2018-09-19 16:00:38 +00:00
import Paper from "@material-ui/core/Paper";
import CircularProgress from "@material-ui/core/CircularProgress";
2018-08-26 14:23:48 +00:00
2018-09-14 15:19:11 +00:00
import { Link } from "react-router-dom";
2018-09-19 16:00:38 +00:00
import { ILevel } from "../models/level";
2018-08-26 14:23:48 +00:00
interface IProps {
2018-09-19 16:00:38 +00:00
getLevels: () => Promise<ILevel[]>;
setLevels: (levels: ILevel[]) => void;
setLoading: (state: boolean) => void;
loading: boolean;
2018-09-06 18:13:29 +00:00
levels: ILevel[];
2018-08-26 14:23:48 +00:00
}
2018-09-19 16:00:38 +00:00
export default class Dashboard extends React.Component<IProps> {
componentDidMount() {
this.props.setLoading(true);
// Fetch the levels
this.props.getLevels().then(res => {
this.props.setLevels(res);
this.props.setLoading(false);
});
2018-08-26 14:23:48 +00:00
}
render() {
2018-09-19 16:00:38 +00:00
if (this.props.loading) {
return <div>
<Grid
container
spacing={0}
direction="column"
alignItems="center"
justify="center"
style={{ minHeight: '100vh' }}>
<Grid item xs={12}>
<Paper className="paper">
<Grid container direction="column" spacing={8}>
<CircularProgress />
</Grid>
</Paper>
</Grid>
</Grid>
</div>;
}
2018-08-26 14:23:48 +00:00
const small = window.matchMedia("(max-width: 700px)").matches;
const cName = small ? "lesson-card-xs" : "lesson-card-lg";
let key = 0;
2018-09-06 18:13:29 +00:00
const levelToCard = (level: ILevel) => {
2018-08-26 14:23:48 +00:00
return <Grid item key={key++}>
<Card style={{
width: small ? window.width - 32 : "300px"
}}>
<CardContent className={cName}>
2018-09-06 18:13:29 +00:00
<Typography variant="title">{`Level ${level.level}`}</Typography>
<Typography variant="title" component="p">{level.name}</Typography>
2018-08-26 14:23:48 +00:00
<br />
<Typography component="p">
{level.description}
2018-08-26 14:23:48 +00:00
</Typography>
</CardContent>
<CardActions>
2018-09-14 15:19:11 +00:00
<Button
component={Link}
to={`/level/${level.level}`}
className="lesson-card-btn">
2018-08-26 14:23:48 +00:00
Zum Level
</Button>
</CardActions>
</Card>
</Grid>;
};
return <Grid container spacing={16} direction="row">
2018-09-06 18:13:29 +00:00
{this.props.levels.map(levelToCard)}
2018-08-26 14:23:48 +00:00
</Grid>
}
};