From 2c9a2e88c79caaca477ac38751eb66b811f32bcf Mon Sep 17 00:00:00 2001 From: Alexander Polynomdivision Date: Wed, 12 Sep 2018 15:15:55 +0200 Subject: [PATCH] feat: Simple implementation of the Review --- src/components/app.tsx | 22 +++++++++-- src/models/vocab.ts | 5 +++ src/pages/level.tsx | 13 +++++- src/pages/review.tsx | 90 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 src/pages/review.tsx diff --git a/src/components/app.tsx b/src/components/app.tsx index 277f6ed..1962f3a 100644 --- a/src/components/app.tsx +++ b/src/components/app.tsx @@ -24,6 +24,7 @@ import Dashboard from "../pages/dashboard"; import LoginPage from "../pages/login"; import LevelListPage from "../pages/levelList"; import LevelPage from "../pages/level"; +import ReviewPage from "../pages/review"; import { ILevel } from "../models/level"; import { IVocab } from "../models/vocab"; @@ -100,11 +101,12 @@ export default class Application extends React.Component<{}, IState> { // TODO: Actually implement this // TODO: Don't fetch this when it was already fetched once. return [{ - latin: "Veni", - german: "", + latin: "Vinum", + german: "Wein", + hint: "Worte auf '-um' sind meistens NeutrUM" id: 0 }, { - latin: "Vidi", + latin: "Vinum (Genitiv)", german: "", id: 1 }, { @@ -113,6 +115,11 @@ export default class Application extends React.Component<{}, IState> { hint: "Wird \"Viki\" und nicht \"Vichi\" ausgesprochen", mnemonic: "Merk dir das Wort mit Caesars berühmten Worten: \"Veni Vidi Vici\"; Er kam, sah und siegte", id: 2 + }, { + latin: "fuga", + german: "Flucht", + hint: "Worte auf \"-a\" sind FeminA", + id: 3 }] as IVocab[]; } @@ -241,6 +248,15 @@ export default class Application extends React.Component<{}, IState> { return ; } }} /> + { + if (this.isAuthenticated()) { + return ; + } else { + return ; + } + }} /> ; diff --git a/src/models/vocab.ts b/src/models/vocab.ts index 0aa95d1..ed7343a 100644 --- a/src/models/vocab.ts +++ b/src/models/vocab.ts @@ -1,3 +1,8 @@ +export enum ReviewMode { + GER_TO_LAT, + LAT_TO_GER, +} + export interface IVocab { german: string; latin: string; diff --git a/src/pages/level.tsx b/src/pages/level.tsx index 146ea54..ae405c4 100644 --- a/src/pages/level.tsx +++ b/src/pages/level.tsx @@ -8,6 +8,8 @@ import Typography from "@material-ui/core/Typography"; import Card from "@material-ui/core/Card"; import CardContent from "@material-ui/core/CardContent"; +import { Redirect } from "react-router-dom"; + import { IVocab } from "../models/vocab"; interface IProps { @@ -19,6 +21,7 @@ interface IProps { interface IState { currentVocab: IVocab; lookedAt: number[]; + toReview: boolean; }; export default class LevelPage extends React.Component { @@ -30,6 +33,7 @@ export default class LevelPage extends React.Component { this.state = { currentVocab: this.props.levelVocab(this.props.id)[0], lookedAt: [0], + toReview: false, }; } @@ -65,13 +69,20 @@ export default class LevelPage extends React.Component { {this.props.levelVocab(this.props.id).map(this.renderVocabListItem)} {/* TODO*/} - alert("Übung")}> + this.setState({ + toReview: true, + })}> Zur Übung + { + this.state.toReview ? ( + + ) : undefined + } diff --git a/src/pages/review.tsx b/src/pages/review.tsx new file mode 100644 index 0000000..7a4bf96 --- /dev/null +++ b/src/pages/review.tsx @@ -0,0 +1,90 @@ +import * as React from "react"; + +import Card from "@material-ui/core/Card"; +import TextField from "@material-ui/core/TextField"; +import Grid from "@material-ui/core/Grid"; +import Button from "@material-ui/core/Button"; +import Typography from "@material-ui/core/Button"; + +import { IVocab, ReviewMode } from "../models/vocab"; + +interface IProps { + levelId: number; + vocabByLevel: (level: number) => IVocab[]; +} + +interface IState { + input: string; + current: number; +} + +export default class ReviewPage extends React.Component { + private vocab: IVocab[] = []; + constructor(props: any) { + super(props); + + this.state = { + input: "", + current: 0, + }; + + const { vocabByLevel, levelId } = this.props; + this.vocab = vocabByLevel(levelId); + + this.currentVocab = this.currentVocab.bind(this); + } + + currentVocab() { + return this.vocab[this.state.current]; + } + + checkInput = () => { + const current = this.currentVocab(); + + // Check if the user's answer was correct + // TODO: Levensthein-Distance? + if (this.state.input === current.german) { + // TODO: Show it's correct + console.log("Hell yeah"); + + // Show the next vocab word + if (this.state.current + 1 >= this.vocab.length) { + // TODO: Go to a summary screen + } else { + // Increase the vocab + this.setState({ + current: this.state.current + 1, + }); + } + } else { + // TODO: Show it's wrong + console.log("Hell no"); + } + + // TODO: Show a snackbar for showing the updated score + } + + render() { + return
+ + + + +

+ {this.vocab[this.state.current].latin} +

+ this.setState({ + input: ev.target.value, + })} /> + +
+
+
+
+
; + } +};