fix: All vocab items now get turned into review cards

This commit is contained in:
Alexander Polynomdivision 2018-10-02 13:38:24 +02:00
parent 2b0d472754
commit cb452a3c54
2 changed files with 71 additions and 28 deletions

View File

@ -50,8 +50,8 @@ export enum ReviewQType {
NOMEN_GENITIV, NOMEN_GENITIV,
NOMEN_GENUS, NOMEN_GENUS,
ADJ_NOM_A, ADJ_ENDUNG_F,
ADJ_NOM_B, ADJ_ENDUNG_N,
VERB_PRAESENS, VERB_PRAESENS,
VERB_PERFEKT, VERB_PERFEKT,
@ -77,12 +77,10 @@ export function reviewQTypeToStr(type: ReviewQType): string {
return "Genitiv"; return "Genitiv";
case ReviewQType.NOMEN_GENUS: case ReviewQType.NOMEN_GENUS:
return "Genus"; return "Genus";
case ReviewQType.ADJ_NOM_A: case ReviewQType.ADJ_ENDUNG_F:
// TODO return "Endung feminin";
return "Nominativ A"; case ReviewQType.ADJ_ENDUNG_N:
case ReviewQType.ADJ_NOM_B: return "Endung neutrum";
// TODO
return "Nominativ B";
case ReviewQType.VERB_PRAESENS: case ReviewQType.VERB_PRAESENS:
return "1. Person Präsens"; return "1. Person Präsens";
case ReviewQType.VERB_PERFEKT: case ReviewQType.VERB_PERFEKT:
@ -97,27 +95,70 @@ export function reviewQTypeToStr(type: ReviewQType): string {
export function vocabToReviewCard(vocab: IVocab): IReviewCard[] { export function vocabToReviewCard(vocab: IVocab): IReviewCard[] {
switch (vocab.type) { switch (vocab.type) {
case VocabType.NOMEN: case VocabType.NOMEN:
const latin = vocab.latin as INomenData; const nData = vocab.latin as INomenData;
return [{ return [{
// Latin -> German // Latin -> German
question: latin.grundform, question: nData.grundform,
answers: vocab.german, answers: vocab.german,
qtype: ReviewQType.GERMAN, qtype: ReviewQType.GERMAN,
id: vocab.id, id: vocab.id,
}, { }, {
// Latin -> Genitiv // Latin -> Genitiv
question: latin.grundform, question: nData.grundform,
answers: [latin.genitiv], answers: [nData.genitiv],
qtype: ReviewQType.NOMEN_GENITIV, qtype: ReviewQType.NOMEN_GENITIV,
id: vocab.id, id: vocab.id,
}, { }, {
// Latin -> Genus // Latin -> Genus
question: latin.grundform, question: nData.grundform,
answers: [latin.genus], answers: [nData.genus],
qtype: ReviewQType.NOMEN_GENUS, qtype: ReviewQType.NOMEN_GENUS,
id: vocab.id, id: vocab.id,
}]; }];
case VocabType.VERB:
const vData = vocab.latin as IVerbData;
return [{
// Latin -> German
question: vData.grundform,
answers: vocab.german,
qtype: ReviewQType.GERMAN,
id: vocab.id,
}, {
// Latin -> Präsens
question: vData.grundform,
answers: [vData.praesens],
qtype: ReviewQType.VERB_PRAESENS,
id: vocab.id,
}, {
// Latin -> Perfekt
question: vData.grundform,
answers: [vData.perfekt],
qtype: ReviewQType.VERB_PERFEKT,
id: vocab.id,
}];
case VocabType.ADJEKTIV:
const aData = vocab.latin as IAdjektivData;
return [{
// Latin -> German
question: aData.grundform,
answers: vocab.german,
qtype: ReviewQType.GERMAN,
id: vocab.id,
}, {
// Latin -> Endung f
question: aData.grundform,
answers: [aData.endung_f],
qtype: ReviewQType.ADJ_ENDUNG_F,
id: vocab.id,
}, {
// Latin -> Perfekt
question: aData.grundform,
answers: [aData.endung_n],
qtype: ReviewQType.ADJ_ENDUNG_N,
id: vocab.id,
}];
default: default:
// TODO: Remove after removing Adverbien
return []; return [];
} }
} }

View File

@ -67,22 +67,12 @@ const ReviewPageWithRouter = withRouter(
private sm2_metadata: any = {}; private sm2_metadata: any = {};
private score_delta = 0; private score_delta = 0;
constructor(props: any) { componentDidMount() {
super(props);
// Hide the drawer button // Hide the drawer button
this.props.drawerButtonState(false); this.props.drawerButtonState(false);
const vocToQueue = () => { // Show a loading spinner
this.vocab.forEach((vocab) => { this.props.setLoading(true);
vocabToReviewCard(vocab).forEach(this.reviewQueue.enqueue);
});
this.props.setReview(this.reviewQueue.dequeue(), {
correct: 0,
wrong: 0,
});
this.props.setLoading(false);
};
// Get the correct vocabulary // Get the correct vocabulary
const { reviewType, vocabByLevel, levelId, vocabByQueue } = this.props; const { reviewType, vocabByLevel, levelId, vocabByQueue } = this.props;
@ -101,8 +91,20 @@ const ReviewPageWithRouter = withRouter(
}[reviewType]; }[reviewType];
getVocab().then((res: IVocab[]) => { getVocab().then((res: IVocab[]) => {
// Stop the loading
this.props.setLoading(false);
this.vocab = res; this.vocab = res;
vocToQueue();
// Convert the vocab items into review queue cards
res.forEach(vocab => {
vocabToReviewCard(vocab).forEach(this.reviewQueue.enqueue);
});
// Set the initial vocabulary card
this.props.setReview(this.reviewQueue.dequeue(), {
correct: 0,
wrong: 0,
});
}); });
} }