Enhance logging and prevent redundant execution in VocabLessonView

- Added console logging to provide better feedback during lesson loading and completion checks.
- Improved loadLesson and checkLessonCompletion methods to prevent multiple executions and enhance user experience.
- Updated error handling to include more descriptive logging for easier debugging.
This commit is contained in:
Torsten Schulz (local)
2026-01-19 22:27:22 +01:00
parent 7f57ecc35e
commit 2eee7bb0c1

View File

@@ -443,8 +443,12 @@ export default {
methods: { methods: {
async loadLesson() { async loadLesson() {
// Verhindere mehrfaches Laden // Verhindere mehrfaches Laden
if (this.loading) return; if (this.loading) {
console.log('[VocabLessonView] loadLesson übersprungen - bereits am Laden');
return;
}
console.log('[VocabLessonView] loadLesson gestartet für lessonId:', this.lessonId);
this.loading = true; this.loading = true;
// Setze Antworten und Ergebnisse zurück // Setze Antworten und Ergebnisse zurück
this.exerciseAnswers = {}; this.exerciseAnswers = {};
@@ -456,13 +460,8 @@ export default {
try { try {
const res = await apiClient.get(`/api/vocab/lessons/${this.lessonId}`); const res = await apiClient.get(`/api/vocab/lessons/${this.lessonId}`);
this.lesson = res.data; this.lesson = res.data;
console.log('[VocabLessonView] Geladene Lektion:', this.lesson); console.log('[VocabLessonView] Geladene Lektion:', this.lesson?.id, this.lesson?.title);
console.log('[VocabLessonView] Übungen:', this.lesson?.grammarExercises); console.log('[VocabLessonView] Übungen:', this.lesson?.grammarExercises?.length || 0);
console.log('[VocabLessonView] Anzahl Übungen:', this.lesson?.grammarExercises?.length || 0);
console.log('[VocabLessonView] activeTab:', this.activeTab);
console.log('[VocabLessonView] hasExercises:', this.hasExercises);
console.log('[VocabLessonView] importantVocab:', this.importantVocab);
console.log('[VocabLessonView] grammarExplanations:', this.grammarExplanations);
// Initialisiere Übungen aus der Lektion oder lade sie separat // Initialisiere Übungen aus der Lektion oder lade sie separat
if (this.lesson && this.lesson.id) { if (this.lesson && this.lesson.id) {
if (this.lesson.grammarExercises && this.lesson.grammarExercises.length > 0) { if (this.lesson.grammarExercises && this.lesson.grammarExercises.length > 0) {
@@ -475,8 +474,9 @@ export default {
await this.loadGrammarExercises(); await this.loadGrammarExercises();
} }
} }
console.log('[VocabLessonView] loadLesson abgeschlossen');
} catch (e) { } catch (e) {
console.error('Konnte Lektion nicht laden:', e); console.error('[VocabLessonView] Fehler beim Laden der Lektion:', e);
} finally { } finally {
this.loading = false; this.loading = false;
} }
@@ -594,8 +594,10 @@ export default {
const res = await apiClient.post(`/api/vocab/grammar-exercises/${exerciseId}/check`, { answer }); const res = await apiClient.post(`/api/vocab/grammar-exercises/${exerciseId}/check`, { answer });
this.exerciseResults[exerciseId] = res.data; this.exerciseResults[exerciseId] = res.data;
// Prüfe ob alle Übungen bestanden sind // Prüfe ob alle Übungen bestanden sind (mit Verzögerung, um mehrfache Aufrufe zu vermeiden)
await this.checkLessonCompletion(); this.$nextTick(() => {
this.checkLessonCompletion();
});
} catch (e) { } catch (e) {
console.error('Fehler beim Prüfen der Antwort:', e); console.error('Fehler beim Prüfen der Antwort:', e);
alert(e.response?.data?.error || 'Fehler beim Prüfen der Antwort'); alert(e.response?.data?.error || 'Fehler beim Prüfen der Antwort');
@@ -603,19 +605,34 @@ export default {
}, },
async checkLessonCompletion() { async checkLessonCompletion() {
// Verhindere mehrfache Ausführung // Verhindere mehrfache Ausführung
if (this.isCheckingLessonCompletion || this.isNavigatingToNext) return; if (this.isCheckingLessonCompletion || this.isNavigatingToNext) {
console.log('[VocabLessonView] checkLessonCompletion übersprungen - bereits in Ausführung');
return;
}
// Prüfe ob alle Übungen korrekt beantwortet wurden // Prüfe ob alle Übungen korrekt beantwortet wurden
if (!this.lesson || !this.lesson.grammarExercises) return; if (!this.lesson || !this.lesson.grammarExercises) {
console.log('[VocabLessonView] checkLessonCompletion übersprungen - keine Lektion/Übungen');
return;
}
const allExercises = this.lesson.grammarExercises; const allExercises = this.lesson.grammarExercises;
if (allExercises.length === 0) {
console.log('[VocabLessonView] checkLessonCompletion übersprungen - keine Übungen');
return;
}
// Prüfe ob alle Übungen korrekt beantwortet wurden
const allCompleted = allExercises.every(exercise => { const allCompleted = allExercises.every(exercise => {
const result = this.exerciseResults[exercise.id]; const result = this.exerciseResults[exercise.id];
return result && result.correct; return result && result.correct;
}); });
if (allCompleted) { console.log('[VocabLessonView] checkLessonCompletion - allCompleted:', allCompleted, 'Übungen:', allExercises.length, 'Korrekt:', allExercises.filter(ex => this.exerciseResults[ex.id]?.correct).length);
if (allCompleted && !this.isCheckingLessonCompletion) {
this.isCheckingLessonCompletion = true; this.isCheckingLessonCompletion = true;
console.log('[VocabLessonView] Alle Übungen abgeschlossen - starte Fortschritts-Update');
try { try {
// Berechne Gesamt-Score // Berechne Gesamt-Score
@@ -623,6 +640,8 @@ export default {
const correctExercises = allExercises.filter(ex => this.exerciseResults[ex.id]?.correct).length; const correctExercises = allExercises.filter(ex => this.exerciseResults[ex.id]?.correct).length;
const score = Math.round((correctExercises / totalExercises) * 100); const score = Math.round((correctExercises / totalExercises) * 100);
console.log('[VocabLessonView] Score berechnet:', score, '%');
// Aktualisiere Fortschritt // Aktualisiere Fortschritt
await apiClient.put(`/api/vocab/lessons/${this.lessonId}/progress`, { await apiClient.put(`/api/vocab/lessons/${this.lessonId}/progress`, {
completed: true, completed: true,
@@ -630,10 +649,12 @@ export default {
timeSpentMinutes: 0 // TODO: Zeit tracken timeSpentMinutes: 0 // TODO: Zeit tracken
}); });
console.log('[VocabLessonView] Fortschritt aktualisiert - starte Navigation');
// Weiterleitung zur nächsten Lektion // Weiterleitung zur nächsten Lektion
await this.navigateToNextLesson(); await this.navigateToNextLesson();
} catch (e) { } catch (e) {
console.error('Fehler beim Aktualisieren des Fortschritts:', e); console.error('[VocabLessonView] Fehler beim Aktualisieren des Fortschritts:', e);
this.isCheckingLessonCompletion = false; this.isCheckingLessonCompletion = false;
} }
} }