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,17 +1,35 @@
|
||||
import { request } from './client';
|
||||
import type { Dashboard, Exercise, Lesson, ProgressSummary } from './types';
|
||||
|
||||
let pendingDashboardRequest: Promise<Dashboard> | null = null;
|
||||
|
||||
export function fetchDashboard() {
|
||||
return request<Dashboard>('/dashboard');
|
||||
if (!pendingDashboardRequest) {
|
||||
pendingDashboardRequest = request<Dashboard>('/dashboard').finally(() => {
|
||||
pendingDashboardRequest = null;
|
||||
});
|
||||
}
|
||||
return pendingDashboardRequest;
|
||||
}
|
||||
|
||||
export function fetchProgress() {
|
||||
return request<ProgressSummary>('/progress');
|
||||
}
|
||||
|
||||
export function fetchNextLesson() {
|
||||
export async function fetchNextLesson(fresh = false, recentExerciseIds: string[] = []) {
|
||||
if (!fresh && pendingDashboardRequest) {
|
||||
try {
|
||||
const dashboard = await pendingDashboardRequest;
|
||||
return { lesson: dashboard.next_lesson, exercise: dashboard.next_exercise };
|
||||
} catch {
|
||||
// A failed dashboard request should not prevent a direct practice request.
|
||||
}
|
||||
}
|
||||
return request<{ lesson: Lesson; exercise: Exercise }>('/lessons/next', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({})
|
||||
body: JSON.stringify(recentExerciseIds.length ? {
|
||||
previous_exercise_id: recentExerciseIds[recentExerciseIds.length - 1],
|
||||
recent_exercise_ids: recentExerciseIds
|
||||
} : {})
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { BookOpen, Bug, ChartNoAxesColumnIncreasing, LogOut, Mic, MessageCircle
|
||||
import { useEffect, useState } from 'react';
|
||||
import { clearToken, getToken } from '../api/client';
|
||||
import { fetchDebugStatus } from '../api/debug';
|
||||
import type { Exercise, Lesson } from '../api/types';
|
||||
import { DashboardPage } from '../pages/DashboardPage';
|
||||
import { LoginPage } from '../pages/LoginPage';
|
||||
import { RegisterPage } from '../pages/RegisterPage';
|
||||
@@ -14,6 +15,7 @@ import { useHashRoute } from './useHashRoute';
|
||||
export function App() {
|
||||
const [route, setRoute] = useHashRoute(getToken() ? 'dashboard' : 'login');
|
||||
const [debugAvailable, setDebugAvailable] = useState(false);
|
||||
const [practiceSelection, setPracticeSelection] = useState<{ lesson: Lesson; exercise: Exercise } | null>(null);
|
||||
const authed = Boolean(getToken());
|
||||
|
||||
useEffect(() => {
|
||||
@@ -34,15 +36,25 @@ export function App() {
|
||||
};
|
||||
}, [authed]);
|
||||
|
||||
useEffect(() => {
|
||||
if (route !== 'practice') setPracticeSelection(null);
|
||||
}, [route]);
|
||||
|
||||
function handleAuthed() {
|
||||
setRoute('dashboard');
|
||||
}
|
||||
|
||||
function logout() {
|
||||
clearToken();
|
||||
setPracticeSelection(null);
|
||||
setRoute('login');
|
||||
}
|
||||
|
||||
function openDashboardExercise(lesson: Lesson, exercise: Exercise) {
|
||||
setPracticeSelection({ lesson, exercise });
|
||||
setRoute('practice');
|
||||
}
|
||||
|
||||
if (!authed) {
|
||||
return (
|
||||
<main className="auth-shell">
|
||||
@@ -92,8 +104,8 @@ export function App() {
|
||||
</aside>
|
||||
|
||||
<main className="main-view">
|
||||
{route === 'dashboard' && <DashboardPage onPractice={() => setRoute('practice')} />}
|
||||
{route === 'practice' && <PracticePage />}
|
||||
{route === 'dashboard' && <DashboardPage onLoaded={(lesson, exercise) => setPracticeSelection({ lesson, exercise })} onPractice={openDashboardExercise} />}
|
||||
{route === 'practice' && <PracticePage initialSelection={practiceSelection} />}
|
||||
{route === 'conversation' && <ConversationPage />}
|
||||
{route === 'progress' && <ProgressPage />}
|
||||
{route === 'debug' && <DebugPage />}
|
||||
|
||||
@@ -1,18 +1,29 @@
|
||||
import { ArrowRight, Clock, Gauge } from 'lucide-react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { fetchDashboard } from '../api/lessons';
|
||||
import type { Dashboard } from '../api/types';
|
||||
import type { Dashboard, Exercise, Lesson } from '../api/types';
|
||||
|
||||
type Props = {
|
||||
onPractice: () => void;
|
||||
onPractice: (lesson: Lesson, exercise: Exercise) => void;
|
||||
onLoaded: (lesson: Lesson, exercise: Exercise) => void;
|
||||
};
|
||||
|
||||
export function DashboardPage({ onPractice }: Props) {
|
||||
export function DashboardPage({ onPractice, onLoaded }: Props) {
|
||||
const [dashboard, setDashboard] = useState<Dashboard | null>(null);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
fetchDashboard().then(setDashboard).catch((err) => setError(err instanceof Error ? err.message : 'Dashboard konnte nicht geladen werden'));
|
||||
let cancelled = false;
|
||||
fetchDashboard()
|
||||
.then((data) => {
|
||||
if (cancelled) return;
|
||||
setDashboard(data);
|
||||
onLoaded(data.next_lesson, data.next_exercise);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (!cancelled) setError(err instanceof Error ? err.message : 'Dashboard konnte nicht geladen werden');
|
||||
});
|
||||
return () => { cancelled = true; };
|
||||
}, []);
|
||||
|
||||
if (error) return <p className="form-error">{error}</p>;
|
||||
@@ -25,7 +36,7 @@ export function DashboardPage({ onPractice }: Props) {
|
||||
<p className="eyebrow">Heute</p>
|
||||
<h1>A1 Aussprachetraining</h1>
|
||||
</div>
|
||||
<button className="primary-button" onClick={onPractice}>
|
||||
<button className="primary-button" onClick={() => onPractice(dashboard.next_lesson, dashboard.next_exercise)}>
|
||||
<ArrowRight size={18} /> Naechste Uebung
|
||||
</button>
|
||||
</header>
|
||||
|
||||
@@ -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