From ed57b735c2f6beccc063914946de15aff7603de8 Mon Sep 17 00:00:00 2001 From: Matthew Grove Date: Sun, 31 Oct 2021 08:22:23 +0000 Subject: [PATCH 1/4] [FIX] Group stats showing extra incorrect answers From sets not part of the group, when "all sets" is selected --- src/GroupStats.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/GroupStats.js b/src/GroupStats.js index bab4d1f..3fed8d2 100644 --- a/src/GroupStats.js +++ b/src/GroupStats.js @@ -107,8 +107,9 @@ export default withRouter(class GroupStats extends Component { .get() .then((querySnapshot) => { let incorrectAnswers = []; - querySnapshot.docs.map((doc, index, array) => { - if (doc.data().setIds.some(item => groupSetIds.includes(item))) { + querySnapshot.docs + .filter((doc) => doc.data().setIds.some(item => groupSetIds.includes(item))) + .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,8 +144,6 @@ 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; From 746d311fe3c507d8b338b6ddd173532cdf4e50ed Mon Sep 17 00:00:00 2001 From: Matthew Grove Date: Sun, 31 Oct 2021 08:34:31 +0000 Subject: [PATCH 2/4] [FIX] ensure db documents are sorted correctly --- src/GroupStats.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GroupStats.js b/src/GroupStats.js index 3fed8d2..42ad004 100644 --- a/src/GroupStats.js +++ b/src/GroupStats.js @@ -104,6 +104,7 @@ 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 = []; From 357796b491a4fb75b850c054010865250d277a50 Mon Sep 17 00:00:00 2001 From: Matthew Grove Date: Sun, 31 Oct 2021 08:35:08 +0000 Subject: [PATCH 3/4] [FIX] ensure db documents are sorted correctly --- src/MistakesHistory.js | 1 + 1 file changed, 1 insertion(+) 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 = []; From 9e945d444c5fecd51956a6fe6e4e917b2c2e5769 Mon Sep 17 00:00:00 2001 From: Matthew Grove Date: Sun, 31 Oct 2021 08:37:58 +0000 Subject: [PATCH 4/4] [FIX] ensure correct mistake count is shown --- src/GroupStats.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/GroupStats.js b/src/GroupStats.js index 42ad004..a22c588 100644 --- a/src/GroupStats.js +++ b/src/GroupStats.js @@ -108,8 +108,9 @@ export default withRouter(class GroupStats extends Component { .get() .then((querySnapshot) => { let incorrectAnswers = []; - querySnapshot.docs - .filter((doc) => 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({ @@ -148,7 +149,7 @@ export default withRouter(class GroupStats extends Component { }); 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 = [];