From 9e6787fb3fac3f796a235cb187770286f9337ee5 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Mon, 19 Jan 2026 22:33:12 +0100 Subject: [PATCH] Enhance logging and improve vocabulary trainer functionality in VocabLessonView - Added detailed console logging to track the flow of the vocabulary trainer, including checks for available vocabulary and question generation. - Implemented a safeguard against infinite loops when generating choice options by limiting attempts. - Enhanced the buildChoiceOptions method to ensure a minimum number of options, adding generic choices if necessary. - Improved the nextVocabQuestion method with additional logging for better debugging and user feedback. --- frontend/src/views/social/VocabLessonView.vue | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/frontend/src/views/social/VocabLessonView.vue b/frontend/src/views/social/VocabLessonView.vue index 41ed513..2cbccc7 100644 --- a/frontend/src/views/social/VocabLessonView.vue +++ b/frontend/src/views/social/VocabLessonView.vue @@ -721,7 +721,12 @@ export default { }, // Vokabeltrainer-Methoden startVocabTrainer() { - if (!this.importantVocab || this.importantVocab.length === 0) return; + console.log('[VocabLessonView] startVocabTrainer aufgerufen'); + if (!this.importantVocab || this.importantVocab.length === 0) { + console.log('[VocabLessonView] Keine Vokabeln vorhanden'); + return; + } + console.log('[VocabLessonView] Vokabeln gefunden:', this.importantVocab.length); this.vocabTrainerActive = true; this.vocabTrainerPool = [...this.importantVocab]; this.vocabTrainerMode = 'multiple_choice'; @@ -729,7 +734,10 @@ export default { this.vocabTrainerWrong = 0; this.vocabTrainerTotalAttempts = 0; this.vocabTrainerStats = {}; - this.nextVocabQuestion(); + console.log('[VocabLessonView] Rufe nextVocabQuestion auf'); + this.$nextTick(() => { + this.nextVocabQuestion(); + }); }, stopVocabTrainer() { this.vocabTrainerActive = false; @@ -764,13 +772,30 @@ export default { buildChoiceOptions(correctAnswer, allVocabs) { const options = new Set([correctAnswer]); // Füge 3 Distraktoren hinzu - while (options.size < 4 && allVocabs.length > 1) { + let attempts = 0; + const maxAttempts = 50; // Verhindere Endlosschleife + + while (options.size < 4 && allVocabs.length > 1 && attempts < maxAttempts) { + attempts++; const randomVocab = allVocabs[Math.floor(Math.random() * allVocabs.length)]; const distractor = this.vocabTrainerDirection === 'L2R' ? randomVocab.reference : randomVocab.learning; if (distractor !== correctAnswer) { options.add(distractor); } } + + // Falls nicht genug Optionen gefunden wurden, füge generische Optionen hinzu + if (options.size < 4) { + const genericOptions = ['Option A', 'Option B', 'Option C', 'Option D']; + let index = 0; + while (options.size < 4 && index < genericOptions.length) { + if (!options.has(genericOptions[index])) { + options.add(genericOptions[index]); + } + index++; + } + } + // Shuffle const arr = Array.from(options); for (let i = arr.length - 1; i > 0; i--) { @@ -780,7 +805,9 @@ export default { return arr; }, nextVocabQuestion() { + console.log('[VocabLessonView] nextVocabQuestion aufgerufen'); if (!this.vocabTrainerPool || this.vocabTrainerPool.length === 0) { + console.log('[VocabLessonView] Keine Vokabeln im Pool'); this.currentVocabQuestion = null; return; } @@ -799,6 +826,8 @@ export default { key: this.getVocabKey(vocab) }; + console.log('[VocabLessonView] Neue Frage erstellt:', this.currentVocabQuestion.prompt); + // Reset UI this.vocabTrainerAnswer = ''; this.vocabTrainerSelectedChoice = null; @@ -806,7 +835,9 @@ export default { // Erstelle Choice-Optionen für Multiple Choice if (this.vocabTrainerMode === 'multiple_choice') { + console.log('[VocabLessonView] Erstelle Choice-Optionen...'); this.vocabTrainerChoiceOptions = this.buildChoiceOptions(this.currentVocabQuestion.answer, this.vocabTrainerPool); + console.log('[VocabLessonView] Choice-Optionen erstellt:', this.vocabTrainerChoiceOptions.length); } // Fokussiere Eingabefeld im Typing-Modus