'use client' import { useState, useEffect, useCallback } from 'react' import { CrawlSource, api } from '../_types' export function SourcesTab() { const [sources, setSources] = useState([]) const [loading, setLoading] = useState(true) const [showForm, setShowForm] = useState(false) const [formName, setFormName] = useState('') const [formPath, setFormPath] = useState('') const [testResult, setTestResult] = useState>({}) const loadSources = useCallback(async () => { setLoading(true) try { const data = await api('sources') setSources(data || []) } catch { /* ignore */ } setLoading(false) }, []) useEffect(() => { loadSources() }, [loadSources]) const handleCreate = async () => { if (!formName || !formPath) return await api('sources', { method: 'POST', body: JSON.stringify({ name: formName, path: formPath }), }) setFormName('') setFormPath('') setShowForm(false) loadSources() } const handleDelete = async (id: string) => { await api(`sources/${id}`, { method: 'DELETE' }) loadSources() } const handleToggle = async (source: CrawlSource) => { await api(`sources/${source.id}`, { method: 'PUT', body: JSON.stringify({ enabled: !source.enabled }), }) loadSources() } const handleTest = async (id: string) => { setTestResult(prev => ({ ...prev, [id]: 'testing...' })) const result = await api(`sources/${id}/test`, { method: 'POST' }) setTestResult(prev => ({ ...prev, [id]: result?.message || 'Fehler' })) } return (

Crawl-Quellen

{showForm && (
setFormName(e.target.value)} placeholder="z.B. Compliance-Ordner" className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-purple-500" />
setFormPath(e.target.value)} placeholder="z.B. compliance-docs" className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-purple-500" />
)} {loading ? (
Laden...
) : sources.length === 0 ? (

Keine Quellen konfiguriert

Erstellen Sie eine Crawl-Quelle um Dokumente zu scannen.

) : (
{sources.map(s => (
{s.name}
{s.path}
Tiefe: {s.max_depth} | Formate: {(typeof s.file_extensions === 'string' ? JSON.parse(s.file_extensions) : s.file_extensions).join(', ')}
{testResult[s.id] && ( {testResult[s.id]} )}
))}
)}
) }