'use client' import React, { useState, useEffect } from 'react' import { useTheme } from '@/lib/ThemeContext' import { Sidebar } from '@/components/Sidebar' import { UnitCard } from '@/components/learn/UnitCard' interface LearningUnit { id: string label: string meta: string title: string topic: string | null grade_level: string | null status: string vocabulary_count?: number created_at: string } function getBackendUrl() { if (typeof window === 'undefined') return 'http://localhost:8001' const { hostname, protocol } = window.location if (hostname === 'localhost') return 'http://localhost:8001' return `${protocol}//${hostname}:8001` } export default function LearnPage() { const { isDark } = useTheme() const [units, setUnits] = useState([]) const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState(null) const glassCard = isDark ? 'bg-white/10 backdrop-blur-xl border border-white/10' : 'bg-white/80 backdrop-blur-xl border border-black/5' useEffect(() => { loadUnits() }, []) const loadUnits = async () => { setIsLoading(true) try { const resp = await fetch(`${getBackendUrl()}/api/learning-units/`) if (!resp.ok) throw new Error(`HTTP ${resp.status}`) const data = await resp.json() setUnits(data) } catch (err: any) { setError(err.message) } finally { setIsLoading(false) } } const handleDelete = async (unitId: string) => { try { const resp = await fetch(`${getBackendUrl()}/api/learning-units/${unitId}`, { method: 'DELETE' }) if (resp.ok) { setUnits((prev) => prev.filter((u) => u.id !== unitId)) } } catch (err) { console.error('Delete failed:', err) } } return (
{/* Background Blobs */}
{/* Sidebar */}
{/* Main Content */}
{/* Header */}

Meine Lernmodule

Karteikarten, Quiz und Lueckentexte aus deinen Vokabeln

{/* Content */}
{isLoading && (
)} {error && (

Fehler: {error}

)} {!isLoading && !error && units.length === 0 && (

Noch keine Lernmodule

Scanne eine Schulbuchseite im Vokabel-Arbeitsblatt Generator und klicke "Lernmodule generieren".

Zum Vokabel-Scanner
)} {!isLoading && units.length > 0 && (
{units.map((unit) => ( ))}
)}
) }