feat: Implement setting the last review
This commit is contained in:
@@ -16,7 +16,7 @@ import { IReviewMetadata } from "../models/review";
|
||||
|
||||
interface IProps {
|
||||
nextLevel: () => ILevel;
|
||||
lastReview: () => IReviewMetadata;
|
||||
getLastReview: () => IReviewMetadata;
|
||||
getTopTen: () => ILearner[];
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export default class Dashboard extends React.Component<IProps> {
|
||||
<Typography variant="title">
|
||||
Letzte Wiederholung
|
||||
</Typography>
|
||||
<SummaryTable reviewMeta={this.props.lastReview()} />
|
||||
<SummaryTable reviewMeta={this.props.getLastReview} />
|
||||
</Paper>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@@ -11,7 +11,7 @@ import Popover from "@material-ui/core/Popover";
|
||||
import { Redirect } from "react-router-dom";
|
||||
|
||||
import { IVocab, IReviewCard, vocabToReviewCard, reviewQTypeToStr } from "../models/vocab";
|
||||
import { ReviewType } from "../models/review";
|
||||
import { ReviewType, IReviewMetadata } from "../models/review";
|
||||
|
||||
import { levW } from "../algorithms/levenshtein";
|
||||
import { LEVENSHTEIN_MAX_DISTANCE } from "../config";
|
||||
@@ -23,6 +23,8 @@ interface IProps {
|
||||
vocabByLevel?: (level: number) => IVocab[];
|
||||
vocabByQueue?: () => IVocab[];
|
||||
|
||||
setLastReview: (meta: IReviewMetadata) => void;
|
||||
|
||||
reviewType: ReviewType;
|
||||
|
||||
drawerButtonState: (state: boolean) => void;
|
||||
@@ -32,6 +34,8 @@ interface IState {
|
||||
input: string;
|
||||
current: IReviewCard;
|
||||
|
||||
metadata: IReviewMetadata;
|
||||
|
||||
toSummary: boolean;
|
||||
|
||||
popoverOpen: boolean;
|
||||
@@ -41,7 +45,7 @@ interface IState {
|
||||
|
||||
export default class ReviewPage extends React.Component<IProps, IState> {
|
||||
private vocab: IVocab[] = [];
|
||||
private reviewQueue: Queue<IReviewCard> = new Queue();
|
||||
private reviewQueue: Queue<IReviewCard> = undefined;
|
||||
// Used for positioning the popover
|
||||
private buttonRef: HTMLButtonElement;
|
||||
|
||||
@@ -73,13 +77,20 @@ export default class ReviewPage extends React.Component<IProps, IState> {
|
||||
}
|
||||
|
||||
// Turn the vocabulary into IReviewCards and queue them
|
||||
this.vocab.forEach((vocab) => {
|
||||
vocabToReviewCard(vocab).forEach(this.reviewQueue.enqueue);
|
||||
});
|
||||
if (!this.reviewQueue) {
|
||||
this.reviewQueue = new Queue();
|
||||
this.vocab.forEach((vocab) => {
|
||||
vocabToReviewCard(vocab).forEach(this.reviewQueue.enqueue);
|
||||
});
|
||||
}
|
||||
|
||||
this.state = {
|
||||
input: "",
|
||||
current: this.reviewQueue.dequeue(),
|
||||
metadata: {
|
||||
correct: 0,
|
||||
wrong: 0,
|
||||
},
|
||||
|
||||
toSummary: false,
|
||||
|
||||
@@ -89,6 +100,15 @@ export default class ReviewPage extends React.Component<IProps, IState> {
|
||||
};
|
||||
}
|
||||
|
||||
increaseMeta = (correct: number, wrong: number): IReviewMetadata => {
|
||||
const { metadata } = this.state;
|
||||
|
||||
return {
|
||||
wrong: metadata.wrong + wrong,
|
||||
correct: metadata.correct + correct,
|
||||
};
|
||||
}
|
||||
|
||||
vocabFromId = (id: number) => {
|
||||
return this.vocab.find((el) => el.id === this.state.current.id);
|
||||
}
|
||||
@@ -104,20 +124,27 @@ export default class ReviewPage extends React.Component<IProps, IState> {
|
||||
// Find the lowest distance
|
||||
const minDist = Math.min(...dists);
|
||||
|
||||
console.log(this.reviewQueue.size());
|
||||
|
||||
// Check if the user's answer was correct
|
||||
if (minDist === 0) {
|
||||
// TODO: Show it's correct?
|
||||
// Show the next vocab word
|
||||
if (this.reviewQueue.size() === 0) {
|
||||
// TODO: Set some data that the summary screen will show
|
||||
// Go to the summary screen
|
||||
this.setState({
|
||||
toSummary: true,
|
||||
}, () => {
|
||||
// Update the "Last Review" data
|
||||
this.props.setLastReview(this.state.metadata);
|
||||
});
|
||||
} else {
|
||||
// Increase the vocab
|
||||
this.setState({
|
||||
current: this.reviewQueue.dequeue(),
|
||||
input: "",
|
||||
// Add one correct answer
|
||||
metadata: this.increaseMeta(1, 0),
|
||||
});
|
||||
}
|
||||
} else if (minDist <= LEVENSHTEIN_MAX_DISTANCE) {
|
||||
@@ -140,6 +167,7 @@ export default class ReviewPage extends React.Component<IProps, IState> {
|
||||
popoverColor: "red",
|
||||
// TODO: Or maybe don't reset the text
|
||||
input: "",
|
||||
metadata: this.increaseMeta(0, 1),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user