From b5582045a9845e6a26d3c3d193a039de6e938de3 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 3 Jun 2026 16:50:28 +0200 Subject: [PATCH] feat: verbessere Fehlerbehandlung und optimiere das Laden von Vokabeln im VocabPracticeDialog --- .../socialnetwork/VocabPracticeDialog.vue | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/frontend/src/dialogues/socialnetwork/VocabPracticeDialog.vue b/frontend/src/dialogues/socialnetwork/VocabPracticeDialog.vue index 45581eb..7722ca7 100644 --- a/frontend/src/dialogues/socialnetwork/VocabPracticeDialog.vue +++ b/frontend/src/dialogues/socialnetwork/VocabPracticeDialog.vue @@ -763,48 +763,49 @@ export default { this.next(); return; } - this.loading = true; + this.loading = true; try { - let res; - let courseDueRes = null; - // Wenn SRS-Modus auf Kurs-Ebene, lade kursweite fällige Items (Server liefert totalDueCount) - if (this.srsMode && this.openParams.courseId && !this.openParams.lessonId) { - try { - courseDueRes = await apiClient.get(`/api/vocab/courses/${this.openParams.courseId}/srs/due`, { params: { limit: 100 } }); - } catch (e) { - // ignore, fallback to lesson/chapters/vocabs endpoints - courseDueRes = null; - } + let res = null; + let courseDueRes = null; + + // Wenn SRS-Modus auf Kurs-Ebene, lade kursweite fällige Items (Server liefert totalDueCount) + if (this.srsMode && this.openParams.courseId && !this.openParams.lessonId) { + try { + courseDueRes = await apiClient.get(`/api/vocab/courses/${this.openParams.courseId}/srs/due`, { params: { limit: 100 } }); + } catch (err) { + courseDueRes = null; } - if (courseDueRes && Array.isArray(courseDueRes.data?.items) && courseDueRes.data.items.length > 0) { - // Map server items to pool shape (use itemKey as id) - this.pool = this.normalizePool((courseDueRes.data.items || []).map((it) => ({ - id: it.itemKey, - learning: it.learning, - reference: it.reference, - lessonId: it.lessonId || null - }))); - this.srsServerTotalDue = Number.isFinite(Number(courseDueRes.data?.totalDueCount)) ? Number(courseDueRes.data.totalDueCount) : null; - } else { - if (this.openParams.lessonId) { - if (this.allVocabs && this.openParams.courseId) { - res = await apiClient.get(`/api/vocab/courses/${this.openParams.courseId}/completed-lesson-vocabs`, { - params: { - untilLessonId: this.openParams.lessonId - } - }); - this.pool = this.normalizePool(res.data?.vocabs || []); - } else { - res = await apiClient.get(`/api/vocab/lessons/${this.openParams.lessonId}/vocab-pool`); - this.pool = this.normalizePool(res.data?.vocabs || []); - } - } else if (this.allVocabs) { - res = await apiClient.get(`/api/vocab/languages/${this.openParams.languageId}/vocabs`); - this.pool = this.normalizePool(res.data?.vocabs || []); + } + + if (courseDueRes && Array.isArray(courseDueRes.data?.items) && courseDueRes.data.items.length > 0) { + // Map server items to pool shape (use itemKey as id) + this.pool = this.normalizePool((courseDueRes.data.items || []).map((it) => ({ + id: it.itemKey, + learning: it.learning, + reference: it.reference, + lessonId: it.lessonId || null + }))); + this.srsServerTotalDue = Number.isFinite(Number(courseDueRes.data?.totalDueCount)) ? Number(courseDueRes.data.totalDueCount) : null; } else { - res = await apiClient.get(`/api/vocab/chapters/${this.openParams.chapterId}/vocabs`); - this.pool = this.normalizePool(res.data?.vocabs || []); + // Fallback: lade Lehr- bzw. Kapitel-/Kurs-Vokabeln + if (this.openParams.lessonId) { + if (this.allVocabs && this.openParams.courseId) { + res = await apiClient.get(`/api/vocab/courses/${this.openParams.courseId}/completed-lesson-vocabs`, { + params: { untilLessonId: this.openParams.lessonId } + }); + this.pool = this.normalizePool(res.data?.vocabs || []); + } else { + res = await apiClient.get(`/api/vocab/lessons/${this.openParams.lessonId}/vocab-pool`); + this.pool = this.normalizePool(res.data?.vocabs || []); + } + } else if (this.allVocabs) { + res = await apiClient.get(`/api/vocab/languages/${this.openParams.languageId}/vocabs`); + this.pool = this.normalizePool(res.data?.vocabs || []); + } else { + res = await apiClient.get(`/api/vocab/chapters/${this.openParams.chapterId}/vocabs`); + this.pool = this.normalizePool(res.data?.vocabs || []); } + } } catch (e) { console.error('Reload pool failed:', e); this.pool = [];