Initial commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { request, setToken } from './client';
|
||||
import type { AuthResult } from './types';
|
||||
|
||||
export async function register(email: string, password: string) {
|
||||
const result = await request<AuthResult>('/auth/register', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
password,
|
||||
ui_language: 'de-DE',
|
||||
target_language: 'en-US',
|
||||
daily_goal_minutes: 10
|
||||
})
|
||||
});
|
||||
setToken(result.token);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function login(email: string, password: string) {
|
||||
const result = await request<AuthResult>('/auth/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ email, password })
|
||||
});
|
||||
setToken(result.token);
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
const API_BASE = import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:8080';
|
||||
|
||||
export class ApiError extends Error {
|
||||
status: number;
|
||||
requestId: string;
|
||||
payload: unknown;
|
||||
|
||||
constructor(status: number, message: string, requestId = '', payload: unknown = null) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
this.requestId = requestId;
|
||||
this.payload = payload;
|
||||
}
|
||||
}
|
||||
|
||||
export function getToken() {
|
||||
return localStorage.getItem('speech_token');
|
||||
}
|
||||
|
||||
export function setToken(token: string) {
|
||||
localStorage.setItem('speech_token', token);
|
||||
}
|
||||
|
||||
export function clearToken() {
|
||||
localStorage.removeItem('speech_token');
|
||||
}
|
||||
|
||||
export async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
|
||||
const headers = new Headers(options.headers);
|
||||
const token = getToken();
|
||||
if (token) {
|
||||
headers.set('Authorization', `Bearer ${token}`);
|
||||
}
|
||||
if (options.body && !(options.body instanceof FormData) && !headers.has('Content-Type')) {
|
||||
headers.set('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE}${path}`, {
|
||||
...options,
|
||||
headers
|
||||
});
|
||||
const isJSON = response.headers.get('content-type')?.includes('application/json');
|
||||
const requestId = response.headers.get('x-request-id') ?? '';
|
||||
const payload = isJSON ? await response.json() : await response.text();
|
||||
|
||||
if (!response.ok) {
|
||||
const message = typeof payload === 'object' && payload?.error ? payload.error : response.statusText;
|
||||
throw new ApiError(response.status, message, requestId, payload);
|
||||
}
|
||||
return payload as T;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { request } from './client';
|
||||
import type { TeacherResponse } from './types';
|
||||
|
||||
export type ConversationResponse = {
|
||||
session?: { id: string };
|
||||
turn?: { text: string };
|
||||
user_turn?: { text: string };
|
||||
teacher_turn?: { text: string };
|
||||
teacher: TeacherResponse;
|
||||
audio?: { mime_type: string; base64: string } | null;
|
||||
};
|
||||
|
||||
export function startConversation() {
|
||||
return request<ConversationResponse>('/conversation/start', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({})
|
||||
});
|
||||
}
|
||||
|
||||
export function sendConversationTurn(sessionId: string, text: string) {
|
||||
return request<ConversationResponse>(`/conversation/${sessionId}/turn`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ text })
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { request } from './client';
|
||||
|
||||
export type DebugCheck = {
|
||||
ok: boolean;
|
||||
status: string;
|
||||
duration_ms?: number;
|
||||
http_status?: number;
|
||||
error?: string;
|
||||
details?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export type DebugStatus = {
|
||||
request_id: string;
|
||||
debug: {
|
||||
enabled: boolean;
|
||||
verbose: boolean;
|
||||
log_level: string;
|
||||
};
|
||||
config: Record<string, unknown>;
|
||||
checks: {
|
||||
db: DebugDB;
|
||||
azure: DebugCheck;
|
||||
flowise: DebugCheck;
|
||||
};
|
||||
};
|
||||
|
||||
export type DebugDB = {
|
||||
ok: boolean;
|
||||
counts: Record<string, number>;
|
||||
seed_language_count: number;
|
||||
seed_exercise_count: number;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
export function fetchDebugStatus() {
|
||||
return request<DebugStatus>('/debug/status');
|
||||
}
|
||||
|
||||
export function fetchDebugDB() {
|
||||
return request<{ request_id: string; db: DebugDB }>('/debug/db');
|
||||
}
|
||||
|
||||
export function fetchDebugFlowise() {
|
||||
return request<{ request_id: string; flowise: DebugCheck }>('/debug/flowise');
|
||||
}
|
||||
|
||||
export function fetchDebugAzure() {
|
||||
return request<{ request_id: string; azure: DebugCheck }>('/debug/azure');
|
||||
}
|
||||
|
||||
export function fetchDebugRuntime() {
|
||||
return request<{ request_id: string; runtime: Record<string, unknown> }>('/debug/runtime');
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { request } from './client';
|
||||
import type { Dashboard, Exercise, Lesson, ProgressSummary } from './types';
|
||||
|
||||
export function fetchDashboard() {
|
||||
return request<Dashboard>('/dashboard');
|
||||
}
|
||||
|
||||
export function fetchProgress() {
|
||||
return request<ProgressSummary>('/progress');
|
||||
}
|
||||
|
||||
export function fetchNextLesson() {
|
||||
return request<{ lesson: Lesson; exercise: Exercise }>('/lessons/next', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({})
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { request } from './client';
|
||||
import type { AttemptResponse } from './types';
|
||||
|
||||
export function submitAttempt(exerciseId: string, audio: Blob) {
|
||||
const form = new FormData();
|
||||
form.append('exercise_id', exerciseId);
|
||||
form.append('audio', audio, `attempt-${Date.now()}.wav`);
|
||||
return request<AttemptResponse>('/practice/attempts', {
|
||||
method: 'POST',
|
||||
body: form
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
export type User = {
|
||||
id: string;
|
||||
email: string;
|
||||
ui_language: string;
|
||||
created_at: string;
|
||||
};
|
||||
|
||||
export type LearnerProfile = {
|
||||
id: string;
|
||||
user_id: string;
|
||||
target_language: string;
|
||||
cefr_level: string;
|
||||
daily_goal_minutes: number;
|
||||
};
|
||||
|
||||
export type Lesson = {
|
||||
id: string;
|
||||
target_language: string;
|
||||
cefr_level: string;
|
||||
topic: string;
|
||||
title: string;
|
||||
};
|
||||
|
||||
export type Exercise = {
|
||||
id: string;
|
||||
lesson_id: string;
|
||||
target_language: string;
|
||||
cefr_level: string;
|
||||
type: string;
|
||||
prompt_text: string;
|
||||
target_text: string;
|
||||
difficulty: number;
|
||||
};
|
||||
|
||||
export type WordScore = {
|
||||
word: string;
|
||||
accuracy: number;
|
||||
error_type?: string;
|
||||
phonemes?: string[];
|
||||
highlight: 'good' | 'ok' | 'weak';
|
||||
};
|
||||
|
||||
export type Attempt = {
|
||||
id: string;
|
||||
exercise_id: string;
|
||||
target_language: string;
|
||||
recognized_text: string;
|
||||
overall_score: number;
|
||||
accuracy_score: number;
|
||||
fluency_score: number;
|
||||
completeness_score: number;
|
||||
prosody_score: number;
|
||||
word_scores: WordScore[];
|
||||
teacher_feedback: string;
|
||||
created_at: string;
|
||||
};
|
||||
|
||||
export type ProgressSummary = {
|
||||
total_attempts: number;
|
||||
average_score: number;
|
||||
weak_words: WordScore[] | null;
|
||||
recent_attempts: Attempt[] | null;
|
||||
daily_goal_minutes: number;
|
||||
};
|
||||
|
||||
export type Dashboard = {
|
||||
user: User;
|
||||
profile: LearnerProfile;
|
||||
progress: ProgressSummary;
|
||||
next_lesson: Lesson;
|
||||
next_exercise: Exercise;
|
||||
};
|
||||
|
||||
export type TeacherResponse = {
|
||||
exercise_type: string;
|
||||
target_text: string;
|
||||
teacher_feedback: string;
|
||||
tts_text: string;
|
||||
ssml: string;
|
||||
next_recommendation: string;
|
||||
};
|
||||
|
||||
export type AuthResult = {
|
||||
token: string;
|
||||
user: User;
|
||||
profile: LearnerProfile;
|
||||
};
|
||||
|
||||
export type AttemptResponse = {
|
||||
attempt: Attempt;
|
||||
teacher: TeacherResponse;
|
||||
provider: string;
|
||||
};
|
||||
@@ -0,0 +1,103 @@
|
||||
import { BookOpen, Bug, ChartNoAxesColumnIncreasing, LogOut, Mic, MessageCircle } from 'lucide-react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { clearToken, getToken } from '../api/client';
|
||||
import { fetchDebugStatus } from '../api/debug';
|
||||
import { DashboardPage } from '../pages/DashboardPage';
|
||||
import { LoginPage } from '../pages/LoginPage';
|
||||
import { RegisterPage } from '../pages/RegisterPage';
|
||||
import { PracticePage } from '../pages/PracticePage';
|
||||
import { ProgressPage } from '../pages/ProgressPage';
|
||||
import { ConversationPage } from '../pages/ConversationPage';
|
||||
import { DebugPage } from '../pages/DebugPage';
|
||||
import { useHashRoute } from './useHashRoute';
|
||||
|
||||
export function App() {
|
||||
const [route, setRoute] = useHashRoute(getToken() ? 'dashboard' : 'login');
|
||||
const [debugAvailable, setDebugAvailable] = useState(false);
|
||||
const authed = Boolean(getToken());
|
||||
|
||||
useEffect(() => {
|
||||
if (!authed) {
|
||||
setDebugAvailable(false);
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
fetchDebugStatus()
|
||||
.then(() => {
|
||||
if (!cancelled) setDebugAvailable(true);
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setDebugAvailable(false);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [authed]);
|
||||
|
||||
function handleAuthed() {
|
||||
setRoute('dashboard');
|
||||
}
|
||||
|
||||
function logout() {
|
||||
clearToken();
|
||||
setRoute('login');
|
||||
}
|
||||
|
||||
if (!authed) {
|
||||
return (
|
||||
<main className="auth-shell">
|
||||
{route === 'register' ? (
|
||||
<RegisterPage onDone={handleAuthed} onLogin={() => setRoute('login')} />
|
||||
) : (
|
||||
<LoginPage onDone={handleAuthed} onRegister={() => setRoute('register')} />
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="app-shell">
|
||||
<aside className="sidebar" aria-label="Navigation">
|
||||
<div>
|
||||
<div className="brand">
|
||||
<div className="brand-mark">SL</div>
|
||||
<div>
|
||||
<strong>Speech Learning</strong>
|
||||
<span>A1 English</span>
|
||||
</div>
|
||||
</div>
|
||||
<nav className="nav-list">
|
||||
<button className={route === 'dashboard' ? 'active' : ''} onClick={() => setRoute('dashboard')}>
|
||||
<BookOpen size={18} /> Heute
|
||||
</button>
|
||||
<button className={route === 'practice' ? 'active' : ''} onClick={() => setRoute('practice')}>
|
||||
<Mic size={18} /> Aussprache
|
||||
</button>
|
||||
<button className={route === 'conversation' ? 'active' : ''} onClick={() => setRoute('conversation')}>
|
||||
<MessageCircle size={18} /> Dialog
|
||||
</button>
|
||||
<button className={route === 'progress' ? 'active' : ''} onClick={() => setRoute('progress')}>
|
||||
<ChartNoAxesColumnIncreasing size={18} /> Fortschritt
|
||||
</button>
|
||||
{debugAvailable && (
|
||||
<button className={route === 'debug' ? 'active' : ''} onClick={() => setRoute('debug')}>
|
||||
<Bug size={18} /> Debug
|
||||
</button>
|
||||
)}
|
||||
</nav>
|
||||
</div>
|
||||
<button className="ghost-button" onClick={logout}>
|
||||
<LogOut size={18} /> Logout
|
||||
</button>
|
||||
</aside>
|
||||
|
||||
<main className="main-view">
|
||||
{route === 'dashboard' && <DashboardPage onPractice={() => setRoute('practice')} />}
|
||||
{route === 'practice' && <PracticePage />}
|
||||
{route === 'conversation' && <ConversationPage />}
|
||||
{route === 'progress' && <ProgressPage />}
|
||||
{route === 'debug' && <DebugPage />}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,534 @@
|
||||
:root {
|
||||
color: #17201b;
|
||||
background: #eef1ef;
|
||||
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||
font-size: 16px;
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
background: #eef1ef;
|
||||
}
|
||||
|
||||
button,
|
||||
input {
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
button {
|
||||
border: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.auth-shell {
|
||||
min-height: 100vh;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 24px;
|
||||
background: linear-gradient(135deg, #eef1ef 0%, #dce8df 52%, #f4e7cf 100%);
|
||||
}
|
||||
|
||||
.auth-panel {
|
||||
width: min(100%, 420px);
|
||||
background: #ffffff;
|
||||
border: 1px solid #d9dfdc;
|
||||
border-radius: 8px;
|
||||
padding: 28px;
|
||||
box-shadow: 0 24px 70px rgba(23, 32, 27, 0.12);
|
||||
}
|
||||
|
||||
.auth-heading,
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.auth-heading h1 {
|
||||
margin: 0;
|
||||
font-size: 1.55rem;
|
||||
}
|
||||
|
||||
.brand-mark {
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border-radius: 8px;
|
||||
background: #0e5f47;
|
||||
color: #ffffff;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
color: #4b5750;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
border: 1px solid #cfd8d3;
|
||||
border-radius: 8px;
|
||||
padding: 12px 14px;
|
||||
background: #ffffff;
|
||||
color: #17201b;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
border-color: #0e5f47;
|
||||
outline: 3px solid rgba(14, 95, 71, 0.16);
|
||||
}
|
||||
|
||||
.app-shell {
|
||||
display: grid;
|
||||
grid-template-columns: 260px minmax(0, 1fr);
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
background: #17201b;
|
||||
color: #ffffff;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.brand span {
|
||||
display: block;
|
||||
color: #b8c8c0;
|
||||
margin-top: 3px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.nav-list {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
margin-top: 28px;
|
||||
}
|
||||
|
||||
.nav-list button,
|
||||
.ghost-button,
|
||||
.primary-button,
|
||||
.danger-button,
|
||||
.link-button {
|
||||
min-height: 42px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 9px;
|
||||
border-radius: 8px;
|
||||
padding: 10px 14px;
|
||||
font-weight: 800;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.nav-list button {
|
||||
justify-content: flex-start;
|
||||
background: transparent;
|
||||
color: #dfe9e4;
|
||||
}
|
||||
|
||||
.nav-list button.active,
|
||||
.nav-list button:hover {
|
||||
background: #26352d;
|
||||
}
|
||||
|
||||
.primary-button {
|
||||
background: #0e5f47;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.primary-button:hover {
|
||||
background: #0b4f3b;
|
||||
}
|
||||
|
||||
.danger-button {
|
||||
background: #a7352d;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.ghost-button {
|
||||
background: #e6ece8;
|
||||
color: #17201b;
|
||||
}
|
||||
|
||||
.sidebar .ghost-button {
|
||||
background: #26352d;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.link-button {
|
||||
width: 100%;
|
||||
margin-top: 14px;
|
||||
background: transparent;
|
||||
color: #0e5f47;
|
||||
}
|
||||
|
||||
.main-view {
|
||||
padding: 30px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.view-stack {
|
||||
display: grid;
|
||||
gap: 22px;
|
||||
max-width: 1060px;
|
||||
}
|
||||
|
||||
.view-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.view-header h1 {
|
||||
margin: 0;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
margin: 0 0 6px;
|
||||
color: #66736c;
|
||||
font-weight: 900;
|
||||
text-transform: uppercase;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: #ffffff;
|
||||
border: 1px solid #d9dfdc;
|
||||
border-radius: 8px;
|
||||
padding: 22px;
|
||||
}
|
||||
|
||||
.metric-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.metric {
|
||||
min-height: 128px;
|
||||
display: grid;
|
||||
align-content: space-between;
|
||||
}
|
||||
|
||||
.metric span,
|
||||
.muted {
|
||||
color: #657269;
|
||||
}
|
||||
|
||||
.metric strong {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.lesson-panel,
|
||||
.practice-panel,
|
||||
.result-panel {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.lesson-panel h2,
|
||||
.result-panel h2 {
|
||||
margin: 0;
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.target-text {
|
||||
margin: 0;
|
||||
color: #17201b;
|
||||
font-size: 1.55rem;
|
||||
font-weight: 850;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.word-feedback {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.word {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 34px;
|
||||
padding: 3px 8px;
|
||||
border-radius: 7px;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
.word-good {
|
||||
color: #0b5d37;
|
||||
background: #e5f4ec;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.word-ok {
|
||||
color: #6f5200;
|
||||
background: #fff3c9;
|
||||
border-color: #ead37a;
|
||||
}
|
||||
|
||||
.word-weak {
|
||||
color: #a1221a;
|
||||
background: #ffe7e4;
|
||||
border-color: #efb7b1;
|
||||
text-decoration: underline;
|
||||
transform: rotate(-1.5deg);
|
||||
}
|
||||
|
||||
.action-row,
|
||||
.recorder,
|
||||
.chat-form {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.result-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.debug-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.debug-card {
|
||||
display: grid;
|
||||
align-content: start;
|
||||
gap: 12px;
|
||||
min-height: 210px;
|
||||
}
|
||||
|
||||
.debug-card-head,
|
||||
.debug-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.debug-title {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.debug-title h2,
|
||||
.debug-card h2 {
|
||||
margin: 0;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.debug-good {
|
||||
border-color: #b8dfc9;
|
||||
}
|
||||
|
||||
.debug-weak,
|
||||
.debug-error {
|
||||
border-color: #efb7b1;
|
||||
}
|
||||
|
||||
.debug-object {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.debug-object div {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(110px, 0.45fr) minmax(0, 1fr);
|
||||
gap: 10px;
|
||||
padding: 7px 0;
|
||||
border-top: 1px solid #e2e7e4;
|
||||
}
|
||||
|
||||
.debug-object dt {
|
||||
color: #657269;
|
||||
font-weight: 800;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.debug-object dd {
|
||||
margin: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.score-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.score {
|
||||
min-height: 82px;
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
.score span {
|
||||
color: #526158;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.score strong {
|
||||
font-size: 1.7rem;
|
||||
}
|
||||
|
||||
.score-good {
|
||||
background: #e5f4ec;
|
||||
border-color: #b8dfc9;
|
||||
}
|
||||
|
||||
.score-ok {
|
||||
background: #fff3c9;
|
||||
border-color: #ead37a;
|
||||
}
|
||||
|
||||
.score-weak {
|
||||
background: #ffe7e4;
|
||||
border-color: #efb7b1;
|
||||
}
|
||||
|
||||
.dialogue-panel {
|
||||
min-height: 360px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.bubble {
|
||||
max-width: min(720px, 92%);
|
||||
padding: 12px 14px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.bubble span {
|
||||
display: block;
|
||||
color: #66736c;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 900;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.bubble p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.bubble.teacher {
|
||||
align-self: flex-start;
|
||||
background: #e5f4ec;
|
||||
}
|
||||
|
||||
.bubble.learner {
|
||||
align-self: flex-end;
|
||||
background: #eaf0ff;
|
||||
}
|
||||
|
||||
.chat-form {
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.chat-form input {
|
||||
flex: 1 1 260px;
|
||||
}
|
||||
|
||||
.icon-only {
|
||||
width: 44px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.weak-list,
|
||||
.attempt-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.attempt-row {
|
||||
width: 100%;
|
||||
min-height: 42px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-bottom: 1px solid #e2e7e4;
|
||||
}
|
||||
|
||||
.form-error,
|
||||
.inline-error {
|
||||
color: #a1221a;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.form-error {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.app-shell {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
min-height: auto;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 5;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.nav-list {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.main-view {
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
.view-header,
|
||||
.result-grid {
|
||||
display: grid;
|
||||
}
|
||||
|
||||
.metric-grid,
|
||||
.debug-grid,
|
||||
.score-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.target-text {
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export function useHashRoute(defaultRoute: string): [string, (route: string) => void] {
|
||||
const initial = window.location.hash.replace('#/', '') || defaultRoute;
|
||||
const [route, setRouteState] = useState(initial);
|
||||
|
||||
useEffect(() => {
|
||||
function onHashChange() {
|
||||
setRouteState(window.location.hash.replace('#/', '') || defaultRoute);
|
||||
}
|
||||
window.addEventListener('hashchange', onHashChange);
|
||||
return () => window.removeEventListener('hashchange', onHashChange);
|
||||
}, [defaultRoute]);
|
||||
|
||||
function setRoute(next: string) {
|
||||
window.location.hash = `/${next}`;
|
||||
setRouteState(next);
|
||||
}
|
||||
|
||||
return [route, setRoute];
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import { Mic, Square } from 'lucide-react';
|
||||
import { useRef, useState } from 'react';
|
||||
|
||||
type Props = {
|
||||
onRecorded: (blob: Blob) => void;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
export function AudioRecorder({ onRecorded, disabled }: Props) {
|
||||
const [recording, setRecording] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const streamRef = useRef<MediaStream | null>(null);
|
||||
const contextRef = useRef<AudioContext | null>(null);
|
||||
const processorRef = useRef<ScriptProcessorNode | null>(null);
|
||||
const sourceRef = useRef<MediaStreamAudioSourceNode | null>(null);
|
||||
const chunks = useRef<Float32Array[]>([]);
|
||||
const sampleRate = useRef(44100);
|
||||
|
||||
async function start() {
|
||||
setError('');
|
||||
try {
|
||||
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
||||
const audioContext = new AudioContext();
|
||||
const source = audioContext.createMediaStreamSource(stream);
|
||||
const processor = audioContext.createScriptProcessor(4096, 1, 1);
|
||||
chunks.current = [];
|
||||
sampleRate.current = audioContext.sampleRate;
|
||||
processor.onaudioprocess = (event) => {
|
||||
const input = event.inputBuffer.getChannelData(0);
|
||||
chunks.current.push(new Float32Array(input));
|
||||
};
|
||||
source.connect(processor);
|
||||
processor.connect(audioContext.destination);
|
||||
streamRef.current = stream;
|
||||
contextRef.current = audioContext;
|
||||
processorRef.current = processor;
|
||||
sourceRef.current = source;
|
||||
setRecording(true);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Mikrofon nicht verfuegbar');
|
||||
}
|
||||
}
|
||||
|
||||
function stop() {
|
||||
processorRef.current?.disconnect();
|
||||
sourceRef.current?.disconnect();
|
||||
streamRef.current?.getTracks().forEach((track) => track.stop());
|
||||
void contextRef.current?.close();
|
||||
const merged = mergeBuffers(chunks.current);
|
||||
const downsampled = downsampleBuffer(merged, sampleRate.current, 16000);
|
||||
const wav = encodeWav(downsampled, 16000);
|
||||
onRecorded(new Blob([wav], { type: 'audio/wav' }));
|
||||
setRecording(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="recorder">
|
||||
{recording ? (
|
||||
<button className="danger-button" onClick={stop} type="button">
|
||||
<Square size={18} /> Stop
|
||||
</button>
|
||||
) : (
|
||||
<button className="primary-button" onClick={start} type="button" disabled={disabled}>
|
||||
<Mic size={18} /> Aufnehmen
|
||||
</button>
|
||||
)}
|
||||
{error && <span className="inline-error">{error}</span>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function mergeBuffers(buffers: Float32Array[]) {
|
||||
const length = buffers.reduce((total, buffer) => total + buffer.length, 0);
|
||||
const result = new Float32Array(length);
|
||||
let offset = 0;
|
||||
for (const buffer of buffers) {
|
||||
result.set(buffer, offset);
|
||||
offset += buffer.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function downsampleBuffer(buffer: Float32Array, inputRate: number, outputRate: number) {
|
||||
if (outputRate === inputRate) return buffer;
|
||||
const ratio = inputRate / outputRate;
|
||||
const newLength = Math.round(buffer.length / ratio);
|
||||
const result = new Float32Array(newLength);
|
||||
let offsetResult = 0;
|
||||
let offsetBuffer = 0;
|
||||
|
||||
while (offsetResult < result.length) {
|
||||
const nextOffsetBuffer = Math.round((offsetResult + 1) * ratio);
|
||||
let accum = 0;
|
||||
let count = 0;
|
||||
for (let i = offsetBuffer; i < nextOffsetBuffer && i < buffer.length; i += 1) {
|
||||
accum += buffer[i];
|
||||
count += 1;
|
||||
}
|
||||
result[offsetResult] = accum / count;
|
||||
offsetResult += 1;
|
||||
offsetBuffer = nextOffsetBuffer;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function encodeWav(samples: Float32Array, rate: number) {
|
||||
const buffer = new ArrayBuffer(44 + samples.length * 2);
|
||||
const view = new DataView(buffer);
|
||||
writeString(view, 0, 'RIFF');
|
||||
view.setUint32(4, 36 + samples.length * 2, true);
|
||||
writeString(view, 8, 'WAVE');
|
||||
writeString(view, 12, 'fmt ');
|
||||
view.setUint32(16, 16, true);
|
||||
view.setUint16(20, 1, true);
|
||||
view.setUint16(22, 1, true);
|
||||
view.setUint32(24, rate, true);
|
||||
view.setUint32(28, rate * 2, true);
|
||||
view.setUint16(32, 2, true);
|
||||
view.setUint16(34, 16, true);
|
||||
writeString(view, 36, 'data');
|
||||
view.setUint32(40, samples.length * 2, true);
|
||||
floatTo16BitPCM(view, 44, samples);
|
||||
return view;
|
||||
}
|
||||
|
||||
function floatTo16BitPCM(view: DataView, offset: number, input: Float32Array) {
|
||||
for (let i = 0; i < input.length; i += 1, offset += 2) {
|
||||
const sample = Math.max(-1, Math.min(1, input[i]));
|
||||
view.setInt16(offset, sample < 0 ? sample * 0x8000 : sample * 0x7fff, true);
|
||||
}
|
||||
}
|
||||
|
||||
function writeString(view: DataView, offset: number, value: string) {
|
||||
for (let i = 0; i < value.length; i += 1) {
|
||||
view.setUint8(offset + i, value.charCodeAt(i));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import type { WordScore } from '../api/types';
|
||||
|
||||
type Props = {
|
||||
targetText: string;
|
||||
words?: WordScore[] | null;
|
||||
};
|
||||
|
||||
export function PronunciationText({ targetText, words }: Props) {
|
||||
if (!words || words.length === 0) {
|
||||
return <p className="target-text">{targetText}</p>;
|
||||
}
|
||||
|
||||
return (
|
||||
<p className="target-text word-feedback">
|
||||
{words.map((word, index) => (
|
||||
<span
|
||||
className={`word word-${word.highlight}`}
|
||||
title={`${Math.round(word.accuracy)}% ${word.error_type ?? ''}`}
|
||||
key={`${word.word}-${index}`}
|
||||
>
|
||||
{word.word}
|
||||
</span>
|
||||
))}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
type Props = {
|
||||
label: string;
|
||||
value: number;
|
||||
};
|
||||
|
||||
export function ScoreBadge({ label, value }: Props) {
|
||||
const rounded = Math.round(value || 0);
|
||||
const tone = rounded >= 85 ? 'good' : rounded >= 70 ? 'ok' : 'weak';
|
||||
return (
|
||||
<div className={`score score-${tone}`}>
|
||||
<span>{label}</span>
|
||||
<strong>{rounded}</strong>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"appName": "Speech Learning",
|
||||
"targetLevel": "A1 English"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"appName": "Speech Learning",
|
||||
"targetLevel": "A1 English"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import { App } from './app/App';
|
||||
import './app/styles.css';
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
@@ -0,0 +1,90 @@
|
||||
import { Play, Send } from 'lucide-react';
|
||||
import { FormEvent, useState } from 'react';
|
||||
import { sendConversationTurn, startConversation, type ConversationResponse } from '../api/conversation';
|
||||
|
||||
export function ConversationPage() {
|
||||
const [sessionId, setSessionId] = useState('');
|
||||
const [input, setInput] = useState('');
|
||||
const [turns, setTurns] = useState<Array<{ speaker: string; text: string }>>([]);
|
||||
const [lastAudio, setLastAudio] = useState<ConversationResponse['audio']>(null);
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function start() {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
const response = await startConversation();
|
||||
setSessionId(response.session?.id ?? '');
|
||||
setLastAudio(response.audio);
|
||||
setTurns([{ speaker: 'teacher', text: response.teacher.tts_text || response.teacher.target_text }]);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Dialog konnte nicht gestartet werden');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function submit(event: FormEvent) {
|
||||
event.preventDefault();
|
||||
if (!sessionId || !input.trim()) return;
|
||||
const userText = input.trim();
|
||||
setInput('');
|
||||
setLoading(true);
|
||||
setTurns((current) => [...current, { speaker: 'learner', text: userText }]);
|
||||
try {
|
||||
const response = await sendConversationTurn(sessionId, userText);
|
||||
setLastAudio(response.audio);
|
||||
setTurns((current) => [...current, { speaker: 'teacher', text: response.teacher.tts_text || response.teacher.target_text }]);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Antwort fehlgeschlagen');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
function playAudio() {
|
||||
if (!lastAudio) return;
|
||||
const audio = new Audio(`data:${lastAudio.mime_type};base64,${lastAudio.base64}`);
|
||||
void audio.play();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="view-stack">
|
||||
<header className="view-header">
|
||||
<div>
|
||||
<p className="eyebrow">A1 Rollenspiel</p>
|
||||
<h1>Dialog</h1>
|
||||
</div>
|
||||
<button className="primary-button" onClick={start} disabled={loading}>
|
||||
<Play size={18} /> Start
|
||||
</button>
|
||||
</header>
|
||||
|
||||
{error && <p className="form-error">{error}</p>}
|
||||
|
||||
<section className="panel dialogue-panel">
|
||||
{turns.length === 0 ? (
|
||||
<p className="muted">Starte einen kurzen A1-Dialog.</p>
|
||||
) : (
|
||||
turns.map((turn, index) => (
|
||||
<div className={`bubble ${turn.speaker}`} key={`${turn.speaker}-${index}`}>
|
||||
<span>{turn.speaker === 'teacher' ? 'Teacher' : 'You'}</span>
|
||||
<p>{turn.text}</p>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</section>
|
||||
|
||||
<form className="chat-form" onSubmit={submit}>
|
||||
<input value={input} onChange={(event) => setInput(event.target.value)} placeholder="My name is ..." disabled={!sessionId || loading} />
|
||||
<button className="primary-button" disabled={!sessionId || loading || !input.trim()} type="submit">
|
||||
<Send size={18} /> Senden
|
||||
</button>
|
||||
<button className="ghost-button icon-only" disabled={!lastAudio} onClick={playAudio} type="button" aria-label="Audio abspielen" title="Audio abspielen">
|
||||
<Play size={18} />
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { ArrowRight, Clock, Gauge } from 'lucide-react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { fetchDashboard } from '../api/lessons';
|
||||
import type { Dashboard } from '../api/types';
|
||||
|
||||
type Props = {
|
||||
onPractice: () => void;
|
||||
};
|
||||
|
||||
export function DashboardPage({ onPractice }: 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'));
|
||||
}, []);
|
||||
|
||||
if (error) return <p className="form-error">{error}</p>;
|
||||
if (!dashboard) return <p className="muted">Lade Dashboard...</p>;
|
||||
|
||||
return (
|
||||
<div className="view-stack">
|
||||
<header className="view-header">
|
||||
<div>
|
||||
<p className="eyebrow">Heute</p>
|
||||
<h1>A1 Aussprachetraining</h1>
|
||||
</div>
|
||||
<button className="primary-button" onClick={onPractice}>
|
||||
<ArrowRight size={18} /> Naechste Uebung
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<section className="metric-grid">
|
||||
<div className="panel metric">
|
||||
<Clock size={22} />
|
||||
<span>Tagesziel</span>
|
||||
<strong>{dashboard.profile.daily_goal_minutes} min</strong>
|
||||
</div>
|
||||
<div className="panel metric">
|
||||
<Gauge size={22} />
|
||||
<span>Durchschnitt</span>
|
||||
<strong>{Math.round(dashboard.progress.average_score || 0)}</strong>
|
||||
</div>
|
||||
<div className="panel metric">
|
||||
<ArrowRight size={22} />
|
||||
<span>Versuche</span>
|
||||
<strong>{dashboard.progress.total_attempts}</strong>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="panel lesson-panel">
|
||||
<div>
|
||||
<p className="eyebrow">{dashboard.next_lesson.topic}</p>
|
||||
<h2>{dashboard.next_lesson.title}</h2>
|
||||
<p className="target-text">{dashboard.next_exercise.target_text}</p>
|
||||
</div>
|
||||
<p className="muted">{dashboard.next_exercise.prompt_text}</p>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
import { Activity, Database, RefreshCw, Server, Settings, Waves } from 'lucide-react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { ApiError } from '../api/client';
|
||||
import {
|
||||
fetchDebugAzure,
|
||||
fetchDebugDB,
|
||||
fetchDebugFlowise,
|
||||
fetchDebugRuntime,
|
||||
fetchDebugStatus,
|
||||
type DebugCheck,
|
||||
type DebugDB,
|
||||
type DebugStatus
|
||||
} from '../api/debug';
|
||||
|
||||
type DebugError = {
|
||||
message: string;
|
||||
status?: number;
|
||||
requestId?: string;
|
||||
};
|
||||
|
||||
export function DebugPage() {
|
||||
const [status, setStatus] = useState<DebugStatus | null>(null);
|
||||
const [db, setDB] = useState<DebugDB | null>(null);
|
||||
const [flowise, setFlowise] = useState<DebugCheck | null>(null);
|
||||
const [azure, setAzure] = useState<DebugCheck | null>(null);
|
||||
const [runtime, setRuntime] = useState<Record<string, unknown> | null>(null);
|
||||
const [error, setError] = useState<DebugError | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
void refreshAll();
|
||||
}, []);
|
||||
|
||||
async function refreshAll() {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const next = await fetchDebugStatus();
|
||||
setStatus(next);
|
||||
setDB(next.checks.db);
|
||||
setFlowise(next.checks.flowise);
|
||||
setAzure(next.checks.azure);
|
||||
const runtimeResponse = await fetchDebugRuntime();
|
||||
setRuntime(runtimeResponse.runtime);
|
||||
} catch (err) {
|
||||
setError(toDebugError(err));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function runDB() {
|
||||
await runCheck(async () => setDB((await fetchDebugDB()).db));
|
||||
}
|
||||
|
||||
async function runFlowise() {
|
||||
await runCheck(async () => setFlowise((await fetchDebugFlowise()).flowise));
|
||||
}
|
||||
|
||||
async function runAzure() {
|
||||
await runCheck(async () => setAzure((await fetchDebugAzure()).azure));
|
||||
}
|
||||
|
||||
async function runCheck(fn: () => Promise<void>) {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
await fn();
|
||||
} catch (err) {
|
||||
setError(toDebugError(err));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="view-stack">
|
||||
<header className="view-header">
|
||||
<div>
|
||||
<p className="eyebrow">Systemdiagnose</p>
|
||||
<h1>Debug</h1>
|
||||
</div>
|
||||
<button className="primary-button" onClick={refreshAll} disabled={loading}>
|
||||
<RefreshCw size={18} /> Neu pruefen
|
||||
</button>
|
||||
</header>
|
||||
|
||||
{error && (
|
||||
<section className="panel result-panel debug-error">
|
||||
<h2>Fehler</h2>
|
||||
<p>{error.message}</p>
|
||||
<p className="muted">
|
||||
{error.status ? `HTTP ${error.status}` : 'Kein HTTP-Status'} {error.requestId ? `Request-ID ${error.requestId}` : ''}
|
||||
</p>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<section className="debug-grid">
|
||||
<DebugCheckCard icon={<Database size={21} />} title="Datenbank" check={dbToCheck(db)} onRefresh={runDB} />
|
||||
<DebugCheckCard icon={<Waves size={21} />} title="Azure Speech" check={azure} onRefresh={runAzure} />
|
||||
<DebugCheckCard icon={<Activity size={21} />} title="Flowise" check={flowise} onRefresh={runFlowise} />
|
||||
<DebugObjectCard icon={<Server size={21} />} title="Runtime" value={runtime} />
|
||||
</section>
|
||||
|
||||
<section className="panel result-panel">
|
||||
<div className="debug-title">
|
||||
<Settings size={21} />
|
||||
<h2>Konfiguration</h2>
|
||||
</div>
|
||||
<DebugObject value={status?.config ?? null} />
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function DebugCheckCard({ icon, title, check, onRefresh }: { icon: ReactNode; title: string; check: DebugCheck | null; onRefresh: () => void }) {
|
||||
const tone = check?.ok ? 'good' : 'weak';
|
||||
return (
|
||||
<section className={`panel debug-card debug-${tone}`}>
|
||||
<div className="debug-card-head">
|
||||
<div className="debug-title">
|
||||
{icon}
|
||||
<h2>{title}</h2>
|
||||
</div>
|
||||
<button className="ghost-button icon-only" onClick={onRefresh} aria-label={`${title} pruefen`} title={`${title} pruefen`}>
|
||||
<RefreshCw size={17} />
|
||||
</button>
|
||||
</div>
|
||||
{check ? (
|
||||
<>
|
||||
<strong>{check.ok ? 'OK' : 'Problem'}</strong>
|
||||
<span>{check.status}</span>
|
||||
{check.http_status ? <span>HTTP {check.http_status}</span> : null}
|
||||
{check.duration_ms ? <span>{check.duration_ms} ms</span> : null}
|
||||
{check.error ? <p className="form-error">{check.error}</p> : null}
|
||||
<DebugObject value={check.details ?? null} />
|
||||
</>
|
||||
) : (
|
||||
<p className="muted">Noch nicht geprueft.</p>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function DebugObjectCard({ icon, title, value }: { icon: ReactNode; title: string; value: Record<string, unknown> | null }) {
|
||||
return (
|
||||
<section className="panel debug-card">
|
||||
<div className="debug-title">
|
||||
{icon}
|
||||
<h2>{title}</h2>
|
||||
</div>
|
||||
<DebugObject value={value} />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function DebugObject({ value }: { value: Record<string, unknown> | null }) {
|
||||
if (!value) return <p className="muted">Keine Daten.</p>;
|
||||
return (
|
||||
<dl className="debug-object">
|
||||
{Object.entries(value).map(([key, val]) => (
|
||||
<div key={key}>
|
||||
<dt>{key}</dt>
|
||||
<dd>{formatValue(val)}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
);
|
||||
}
|
||||
|
||||
function dbToCheck(db: DebugDB | null): DebugCheck | null {
|
||||
if (!db) return null;
|
||||
return {
|
||||
ok: db.ok,
|
||||
status: db.ok ? 'reachable' : 'error',
|
||||
error: db.error,
|
||||
details: {
|
||||
...db.counts,
|
||||
seed_language_count: db.seed_language_count,
|
||||
seed_exercise_count: db.seed_exercise_count
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function formatValue(value: unknown) {
|
||||
if (Array.isArray(value)) return value.join(', ');
|
||||
if (typeof value === 'object' && value !== null) return JSON.stringify(value);
|
||||
if (typeof value === 'boolean') return value ? 'true' : 'false';
|
||||
return String(value ?? '');
|
||||
}
|
||||
|
||||
function toDebugError(err: unknown): DebugError {
|
||||
if (err instanceof ApiError) {
|
||||
return { message: err.message, status: err.status, requestId: err.requestId };
|
||||
}
|
||||
if (err instanceof Error) {
|
||||
return { message: err.message };
|
||||
}
|
||||
return { message: 'Unbekannter Fehler' };
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { LogIn } from 'lucide-react';
|
||||
import { FormEvent, useState } from 'react';
|
||||
import { login } from '../api/auth';
|
||||
|
||||
type Props = {
|
||||
onDone: () => void;
|
||||
onRegister: () => void;
|
||||
};
|
||||
|
||||
export function LoginPage({ onDone, onRegister }: Props) {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function submit(event: FormEvent) {
|
||||
event.preventDefault();
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
await login(email, password);
|
||||
onDone();
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Login fehlgeschlagen');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="auth-panel">
|
||||
<div className="auth-heading">
|
||||
<div className="brand-mark">SL</div>
|
||||
<h1>Einloggen</h1>
|
||||
</div>
|
||||
<form onSubmit={submit} className="form-grid">
|
||||
<label>
|
||||
E-Mail
|
||||
<input value={email} onChange={(event) => setEmail(event.target.value)} type="email" autoComplete="email" required />
|
||||
</label>
|
||||
<label>
|
||||
Passwort
|
||||
<input value={password} onChange={(event) => setPassword(event.target.value)} type="password" autoComplete="current-password" required />
|
||||
</label>
|
||||
{error && <p className="form-error">{error}</p>}
|
||||
<button className="primary-button" disabled={loading} type="submit">
|
||||
<LogIn size={18} /> Login
|
||||
</button>
|
||||
</form>
|
||||
<button className="link-button" onClick={onRegister} type="button">
|
||||
Account erstellen
|
||||
</button>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { RotateCcw, Send } from 'lucide-react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { fetchNextLesson } from '../api/lessons';
|
||||
import { submitAttempt } from '../api/practice';
|
||||
import type { AttemptResponse, Exercise, Lesson } from '../api/types';
|
||||
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);
|
||||
const [audio, setAudio] = useState<Blob | null>(null);
|
||||
const [result, setResult] = useState<AttemptResponse | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
loadNext();
|
||||
}, []);
|
||||
|
||||
async function loadNext() {
|
||||
setError('');
|
||||
setAudio(null);
|
||||
setResult(null);
|
||||
try {
|
||||
const next = await fetchNextLesson();
|
||||
setLesson(next.lesson);
|
||||
setExercise(next.exercise);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Uebung konnte nicht geladen werden');
|
||||
}
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
if (!exercise || !audio) return;
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
setResult(await submitAttempt(exercise.id, audio));
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Bewertung fehlgeschlagen');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (error) return <p className="form-error">{error}</p>;
|
||||
if (!lesson || !exercise) return <p className="muted">Lade Uebung...</p>;
|
||||
|
||||
return (
|
||||
<div className="view-stack">
|
||||
<header className="view-header">
|
||||
<div>
|
||||
<p className="eyebrow">{lesson.title}</p>
|
||||
<h1>Aussprache</h1>
|
||||
</div>
|
||||
<button className="ghost-button" onClick={loadNext}>
|
||||
<RotateCcw size={18} /> Andere Uebung
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<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}>
|
||||
<Send size={18} /> Bewerten
|
||||
</button>
|
||||
</div>
|
||||
{audio && !result && <p className="muted">Aufnahme bereit. Jetzt bewerten.</p>}
|
||||
</section>
|
||||
|
||||
{result && (
|
||||
<section className="result-grid">
|
||||
<div className="panel result-panel">
|
||||
<h2>Bewertung</h2>
|
||||
<div className="score-grid">
|
||||
<ScoreBadge label="Gesamt" value={result.attempt.overall_score} />
|
||||
<ScoreBadge label="Accuracy" value={result.attempt.accuracy_score} />
|
||||
<ScoreBadge label="Fluency" value={result.attempt.fluency_score} />
|
||||
<ScoreBadge label="Completeness" value={result.attempt.completeness_score} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="panel result-panel">
|
||||
<h2>Lehrerfeedback</h2>
|
||||
<p>{result.teacher.teacher_feedback}</p>
|
||||
<p className="muted">{result.teacher.next_recommendation}</p>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { fetchProgress } from '../api/lessons';
|
||||
import type { ProgressSummary } from '../api/types';
|
||||
import { ScoreBadge } from '../components/ScoreBadge';
|
||||
|
||||
export function ProgressPage() {
|
||||
const [progress, setProgress] = useState<ProgressSummary | null>(null);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
fetchProgress().then(setProgress).catch((err) => setError(err instanceof Error ? err.message : 'Fortschritt konnte nicht geladen werden'));
|
||||
}, []);
|
||||
|
||||
if (error) return <p className="form-error">{error}</p>;
|
||||
if (!progress) return <p className="muted">Lade Fortschritt...</p>;
|
||||
|
||||
return (
|
||||
<div className="view-stack">
|
||||
<header className="view-header">
|
||||
<div>
|
||||
<p className="eyebrow">A1 Englisch</p>
|
||||
<h1>Fortschritt</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section className="metric-grid">
|
||||
<div className="panel result-panel">
|
||||
<ScoreBadge label="Durchschnitt" value={progress.average_score} />
|
||||
</div>
|
||||
<div className="panel metric">
|
||||
<span>Versuche</span>
|
||||
<strong>{progress.total_attempts}</strong>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="panel result-panel">
|
||||
<h2>Schwierige Woerter</h2>
|
||||
<div className="weak-list">
|
||||
{(progress.weak_words ?? []).length === 0 ? (
|
||||
<p className="muted">Noch keine Schwachstellen.</p>
|
||||
) : (
|
||||
(progress.weak_words ?? []).map((word) => (
|
||||
<span className={`word word-${word.highlight}`} key={word.word}>
|
||||
{word.word} {Math.round(word.accuracy)}
|
||||
</span>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="panel result-panel">
|
||||
<h2>Letzte Versuche</h2>
|
||||
<div className="attempt-list">
|
||||
{(progress.recent_attempts ?? []).map((attempt) => (
|
||||
<div className="attempt-row" key={attempt.id}>
|
||||
<span>{new Date(attempt.created_at).toLocaleString()}</span>
|
||||
<strong>{Math.round(attempt.overall_score)}</strong>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { UserPlus } from 'lucide-react';
|
||||
import { FormEvent, useState } from 'react';
|
||||
import { register } from '../api/auth';
|
||||
|
||||
type Props = {
|
||||
onDone: () => void;
|
||||
onLogin: () => void;
|
||||
};
|
||||
|
||||
export function RegisterPage({ onDone, onLogin }: Props) {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function submit(event: FormEvent) {
|
||||
event.preventDefault();
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
await register(email, password);
|
||||
onDone();
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Registrierung fehlgeschlagen');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="auth-panel">
|
||||
<div className="auth-heading">
|
||||
<div className="brand-mark">SL</div>
|
||||
<h1>Account erstellen</h1>
|
||||
</div>
|
||||
<form onSubmit={submit} className="form-grid">
|
||||
<label>
|
||||
E-Mail
|
||||
<input value={email} onChange={(event) => setEmail(event.target.value)} type="email" autoComplete="email" required />
|
||||
</label>
|
||||
<label>
|
||||
Passwort
|
||||
<input value={password} onChange={(event) => setPassword(event.target.value)} type="password" autoComplete="new-password" minLength={8} required />
|
||||
</label>
|
||||
{error && <p className="form-error">{error}</p>}
|
||||
<button className="primary-button" disabled={loading} type="submit">
|
||||
<UserPlus size={18} /> Registrieren
|
||||
</button>
|
||||
</form>
|
||||
<button className="link-button" onClick={onLogin} type="button">
|
||||
Zurueck zum Login
|
||||
</button>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
Reference in New Issue
Block a user