fix: Crash because of empty vocabulary list

Array.reduce(...) will crash if the array is empty. So we
just default to 0, if this.vocab is empty.
This commit is contained in:
Alexander Polynomdivision 2018-10-02 18:06:38 +02:00
parent 8754c9b6da
commit 4ba879c531

View File

@ -281,13 +281,17 @@ const ReviewPageWithRouter = withRouter(
// will then deduce the type of acc and curr to be '1|3',
// leads to compiler warnings, as a, b element {1, 3} is not
// element {1, 3}.
const numCards = this.vocab.map((vocab): number => {
// NOTE: We need to check if this.vocab is empty because otherwise
// the '.reduce' call will throw and crash the entire
// application.
// TOFIX: This is pure garbage. Fix this
const numCards = this.vocab.length > 0 ? this.vocab.map((vocab): number => {
if (vocab.type === VocabType.ADVERB) {
return 1;
} else {
return 3;
}
}).reduce((acc, curr) => acc + curr);
}).reduce((acc, curr) => acc + curr) : 0;
const progress = numCards === 0 ? (
0