Flowise-Übungen stabilisieren und Lernfortschritt korrigieren
Vermeide kürzlich angezeigte Sätze bei neuen Übungen und frage Flowise bei Wiederholungen einmal erneut. Validiere strukturierte Antworten, protokolliere die Übungsquelle und schütze nutzerspezifische Übungs-IDs. Berechne schwierige Wörter anhand der neuesten Aussprache pro Wort. Passe das Lehrerfeedback an gute Bewertungen an und verbessere das Laden neuer Übungen im Web. Ergänze gezielte Go-Tests.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { RotateCcw, Send } from 'lucide-react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { fetchNextLesson } from '../api/lessons';
|
||||
import { submitAttempt } from '../api/practice';
|
||||
import type { AttemptResponse, Exercise, Lesson } from '../api/types';
|
||||
@@ -7,28 +7,46 @@ import { AudioRecorder } from '../components/AudioRecorder';
|
||||
import { PronunciationText } from '../components/PronunciationText';
|
||||
import { ScoreBadge } from '../components/ScoreBadge';
|
||||
|
||||
export function PracticePage() {
|
||||
const [lesson, setLesson] = useState<Lesson | null>(null);
|
||||
const [exercise, setExercise] = useState<Exercise | null>(null);
|
||||
type Props = {
|
||||
initialSelection?: { lesson: Lesson; exercise: Exercise } | null;
|
||||
};
|
||||
|
||||
export function PracticePage({ initialSelection }: Props) {
|
||||
const [lesson, setLesson] = useState<Lesson | null>(initialSelection?.lesson ?? null);
|
||||
const [exercise, setExercise] = useState<Exercise | null>(initialSelection?.exercise ?? null);
|
||||
const [audio, setAudio] = useState<Blob | null>(null);
|
||||
const [result, setResult] = useState<AttemptResponse | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [loadingNext, setLoadingNext] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [notice, setNotice] = useState('');
|
||||
const recentExerciseIds = useRef<string[]>(initialSelection?.exercise.id ? [initialSelection.exercise.id] : []);
|
||||
|
||||
useEffect(() => {
|
||||
loadNext();
|
||||
if (!initialSelection) void loadNext();
|
||||
}, []);
|
||||
|
||||
async function loadNext() {
|
||||
async function loadNext(fresh = false) {
|
||||
if (loadingNext) return;
|
||||
setLoadingNext(true);
|
||||
setError('');
|
||||
setNotice('');
|
||||
setAudio(null);
|
||||
setResult(null);
|
||||
try {
|
||||
const next = await fetchNextLesson();
|
||||
const next = await fetchNextLesson(fresh, fresh ? recentExerciseIds.current : []);
|
||||
if (fresh && exercise?.target_text.trim().toLowerCase() === next.exercise.target_text.trim().toLowerCase()) {
|
||||
setNotice('Der Agent hat denselben Satz erneut erzeugt. Bitte versuche es noch einmal.');
|
||||
}
|
||||
setLesson(next.lesson);
|
||||
setExercise(next.exercise);
|
||||
if (next.exercise.id && recentExerciseIds.current[recentExerciseIds.current.length - 1] !== next.exercise.id) {
|
||||
recentExerciseIds.current = [...recentExerciseIds.current, next.exercise.id].slice(-3);
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Uebung konnte nicht geladen werden');
|
||||
} finally {
|
||||
setLoadingNext(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,8 +63,14 @@ export function PracticePage() {
|
||||
}
|
||||
}
|
||||
|
||||
if (error) return <p className="form-error">{error}</p>;
|
||||
if (!lesson || !exercise) return <p className="muted">Lade Uebung...</p>;
|
||||
if (!lesson || !exercise) {
|
||||
return (
|
||||
<div className="view-stack">
|
||||
<p className={error ? 'form-error' : 'muted'}>{error || 'Lade Uebung...'}</p>
|
||||
{error && <button className="ghost-button" disabled={loadingNext} onClick={() => void loadNext(true)}>Erneut versuchen</button>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="view-stack">
|
||||
@@ -55,17 +79,20 @@ export function PracticePage() {
|
||||
<p className="eyebrow">{lesson.title}</p>
|
||||
<h1>Aussprache</h1>
|
||||
</div>
|
||||
<button className="ghost-button" onClick={loadNext}>
|
||||
<RotateCcw size={18} /> Andere Uebung
|
||||
<button className="ghost-button" disabled={loadingNext || loading} onClick={() => void loadNext(true)}>
|
||||
<RotateCcw size={18} /> {loadingNext ? 'Lade neue Uebung...' : 'Andere Uebung'}
|
||||
</button>
|
||||
</header>
|
||||
|
||||
{error && <p className="form-error">{error}</p>}
|
||||
{notice && <p className="muted">{notice}</p>}
|
||||
|
||||
<section className="panel practice-panel">
|
||||
<p className="muted">{exercise.prompt_text}</p>
|
||||
<PronunciationText targetText={exercise.target_text} words={result?.attempt.word_scores} />
|
||||
<div className="action-row">
|
||||
<AudioRecorder onRecorded={setAudio} disabled={loading} />
|
||||
<button className="primary-button" disabled={!audio || loading} onClick={submit}>
|
||||
<AudioRecorder onRecorded={setAudio} disabled={loading || loadingNext} />
|
||||
<button className="primary-button" disabled={!audio || loading || loadingNext} onClick={submit}>
|
||||
<Send size={18} /> Bewerten
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user