feat: Implement a vocabulary view

This commit is contained in:
Alexander Polynomdivision
2018-10-11 14:37:21 +02:00
parent 528c291b70
commit a902d9e8f7
7 changed files with 178 additions and 1 deletions

View File

@@ -8,7 +8,6 @@ import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent';
import Paper from "@material-ui/core/Paper";
import Snackbar from "@material-ui/core/Snackbar";
import CircularProgress from "@material-ui/core/CircularProgress";
import { withRouter } from "react-router-dom";

View File

@@ -0,0 +1,79 @@
import * as React from "react";
import Grid from "@material-ui/core/Grid";
import Typography from "@material-ui/core/Typography";
import Paper from "@material-ui/core/Paper";
import CircularProgress from "@material-ui/core/CircularProgress";
import { IVocab, VocabType } from "../models/vocab";
import VocabularyData from "../components/VocabularyData";
interface IProps {
getVocab: () => Promise<IVocab[]>;
loading: boolean;
vocab: IVocab[];
setLoading: (state: boolean) => void;
setVocab: (vocab: IVocab[]) => void;
}
export default class VocabPage extends React.Component<IProps> {
private uid = 0;
genUID = () => {
return `VOCABPAGE-${this.uid++}`;
}
componentDidMount() {
this.props.setLoading(true);
// TODO: Errorhandling
this.props.getVocab().then(vocab => {
this.props.setVocab(vocab);
this.props.setLoading(false);
});
}
vocabToCard = (voc: IVocab) => {
const vocabTypeToStr = {
[VocabType.NOMEN]: "Nomen",
[VocabType.VERB]: "Verb",
[VocabType.ADJEKTIV]: "Adjektiv",
[VocabType.ADVERB]: "Adverb",
};
return <Paper key={this.genUID()} style={{ marginBottom: 12, padding: 12 }}>
<Typography gutterBottom variant="headline" component="h2">
{`${voc.latin.grundform} (${vocabTypeToStr[voc.type]})`}
</Typography>
<VocabularyData vocab={voc} />
</Paper>;
}
render() {
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>;
}
const { vocab } = this.props;
return <div className="content">
{vocab.map(this.vocabToCard)}
</div>;
}
};