diff --git a/src/GroupStats.js b/src/GroupStats.js index bab4d1f..a22c588 100644 --- a/src/GroupStats.js +++ b/src/GroupStats.js @@ -104,11 +104,14 @@ export default withRouter(class GroupStats extends Component { if (groupSetIds.length > 0) await this.state.db.collection("incorrect_answers") .where("groups", "array-contains", this.props.match.params.groupId) .orderBy("term", "asc") + .orderBy("definition", "asc") .get() .then((querySnapshot) => { let incorrectAnswers = []; - querySnapshot.docs.map((doc, index, array) => { - if (doc.data().setIds.some(item => groupSetIds.includes(item))) { + const docs = querySnapshot.docs + .filter((doc) => doc.data().setIds.some(item => groupSetIds.includes(item))); + docs + .map((doc, index, array) => { if (index === 0 || doc.data().term !== array[index - 1].data().term || doc.data().definition !== array[index - 1].data().definition) { incorrectAnswers.push({ term: doc.data().term, @@ -143,12 +146,10 @@ export default withRouter(class GroupStats extends Component { doc.data().setIds.map((setId) => newState.setsWithHistory[setId] = true); return true; - } - return false; }); newState.incorrectAnswers = incorrectAnswers.sort((a, b) => b.count + b.switchedCount - a.count - a.switchedCount); newState.filteredIncorrectAnswers = newState.incorrectAnswers; - newState.totalIncorrect = querySnapshot.docs.length; + newState.totalIncorrect = docs.length; }) .catch((error) => { newState.incorrectAnswers = []; diff --git a/src/MistakesHistory.js b/src/MistakesHistory.js index 79ea246..ba03b34 100644 --- a/src/MistakesHistory.js +++ b/src/MistakesHistory.js @@ -67,6 +67,7 @@ export default class IncorrectHistory extends Component { this.state.db.collection("incorrect_answers") .where("uid", "==", this.state.user.uid) .orderBy("term", "asc") + .orderBy("definition", "asc") .get() .then(async (querySnapshot) => { let incorrectAnswers = [];