From 61fe4a168a3658b41e050c07b9742c3a7806a2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Latzarus?= Date: Thu, 24 Oct 2024 16:21:18 +0200 Subject: [PATCH] feat(mon-pix): increment self-assessment counters Co-authored-by: Diane Cordier Co-authored-by: Eric Lim --- .../module/element/flashcards/flashcards.gjs | 17 +++++- .../components/module/flashcards_test.gjs | 60 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/mon-pix/app/components/module/element/flashcards/flashcards.gjs b/mon-pix/app/components/module/element/flashcards/flashcards.gjs index 702f5f5a111..8175925ba45 100644 --- a/mon-pix/app/components/module/element/flashcards/flashcards.gjs +++ b/mon-pix/app/components/module/element/flashcards/flashcards.gjs @@ -9,6 +9,8 @@ import ModulixFlashcardsCard from 'mon-pix/components/module/element/flashcards/ import ModulixFlashcardsIntroCard from 'mon-pix/components/module/element/flashcards/flashcards-intro-card'; import ModulixFlashcardsOutroCard from 'mon-pix/components/module/element/flashcards/flashcards-outro-card'; +const INITIAL_COUNTERS_VALUE = { yes: 0, almost: 0, no: 0 }; + export default class ModulixFlashcards extends Component { @tracked /** @@ -31,6 +33,13 @@ export default class ModulixFlashcards extends Component { */ currentCardIndex = 0; + @tracked + /** + * Stores the number of times an answer has been chosen + * @type {object} + */ + counters = { ...INITIAL_COUNTERS_VALUE }; + get currentCard() { return this.args.flashcards.cards[this.currentCardIndex]; } @@ -52,6 +61,7 @@ export default class ModulixFlashcards extends Component { this.currentStep = 'intro'; this.currentCardIndex = 0; this.displayedSideName = 'recto'; + this.counters = { ...INITIAL_COUNTERS_VALUE }; } @action @@ -64,6 +74,10 @@ export default class ModulixFlashcards extends Component { this.displayedSideName = this.displayedSideName === 'recto' ? 'verso' : 'recto'; } + incrementCounterFor(userAssessment) { + this.counters[userAssessment]++; + } + goToNextCard() { if (this.currentCardIndex < this.numberOfCards - 1) { this.currentCardIndex++; @@ -80,6 +94,7 @@ export default class ModulixFlashcards extends Component { cardId: this.currentCard.id, }; this.args.onSelfAssessment(selfAssessmentData); + this.incrementCounterFor(userAssessment); this.goToNextCard(); } @@ -103,7 +118,7 @@ export default class ModulixFlashcards extends Component { {{/if}} {{#if (eq this.currentStep "outro")}} - + {{/if}}