import { useState } from 'react'; import axios from '../services/api'; const diffColors = { added: { bg: 'rgba(34, 197, 94, 0.12)', text: '#22c55e', prefix: '+ ' }, removed: { bg: 'rgba(239, 68, 68, 0.12)', text: '#ef4444', prefix: '- ' }, unchanged: { bg: 'transparent', text: 'var(--muted)', prefix: ' ' }, }; function TextDiffTool() { const [text1, setText1] = useState(''); const [text2, setText2] = useState(''); const [diff, setDiff] = useState(null); const compare = async () => { try { const res = await axios.post('/api/text/diff', { text1, text2 }); setDiff(res.data.diff); } catch { alert('Fehler beim Vergleich'); } }; return (
Text A
Text B
Keine Unterschiede gefunden.
) : ( diff.map((line, i) => { const c = diffColors[line.type] || diffColors.unchanged; return (