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