'use client' import { useState, useEffect, useCallback } from 'react' import { CrawlDocument, api, CLASSIFICATION_LABELS, ALL_CLASSIFICATIONS } from '../_types' export function DocumentsTab() { const [docs, setDocs] = useState([]) const [total, setTotal] = useState(0) const [loading, setLoading] = useState(true) const [filterClass, setFilterClass] = useState('') const [archiving, setArchiving] = useState>({}) const loadDocs = useCallback(async () => { setLoading(true) try { const params = filterClass ? `?classification=${filterClass}` : '' const data = await api(`documents${params}`) setDocs(data?.documents || []) setTotal(data?.total || 0) } catch { /* ignore */ } setLoading(false) }, [filterClass]) useEffect(() => { loadDocs() }, [loadDocs]) const handleReclassify = async (docId: string, newClass: string) => { await api(`documents/${docId}/classify`, { method: 'PUT', body: JSON.stringify({ classification: newClass }), }) loadDocs() } const handleArchive = async (docId: string) => { setArchiving(prev => ({ ...prev, [docId]: true })) try { await api(`documents/${docId}/archive`, { method: 'POST' }) loadDocs() } catch { /* ignore */ } setArchiving(prev => ({ ...prev, [docId]: false })) } const formatSize = (bytes: number) => { if (bytes < 1024) return `${bytes} B` if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB` return `${(bytes / 1024 / 1024).toFixed(1)} MB` } return (

{total} Dokumente

{loading ? (
Laden...
) : docs.length === 0 ? (
Keine Dokumente gefunden. Starten Sie zuerst einen Crawl-Job.
) : (
{docs.map(doc => { const cls = CLASSIFICATION_LABELS[doc.classification || ''] || CLASSIFICATION_LABELS['Sonstiges'] return ( ) })}
Datei Kategorie Konfidenz Groesse Archiv Aktionen
{doc.file_name}
{doc.source_name}
{doc.classification_corrected && ( * )} {doc.classification_confidence != null && (
{(doc.classification_confidence * 100).toFixed(0)}%
)}
{formatSize(doc.file_size_bytes)} {doc.archived ? ( IPFS ) : ( - )} {!doc.archived && ( )}
)}
) }