/** * Diff Viewer — unified diff with syntax coloring * Ball Studios */ import React, { useEffect, useState } from 'react'; import http from '@/api/http'; interface DiffLine { type: 'context' | 'added' | 'removed' | 'header'; content: string; line_old?: number; line_new?: number; } interface Props { serverUuid: string; revision: { id: number; revision_number: number }; onClose: () => void; } export default function DiffViewer({ serverUuid, revision, onClose }: Props) { const [lines, setLines] = useState([]); const [binary, setBinary] = useState(false); const [loading, setLoading] = useState(true); useEffect(() => { http.get(`/api/client/servers/${serverUuid}/addons/files/revisions/${revision.id}/diff`) .then(({ data }) => { setBinary(data.binary); setLines(data.lines ?? []); }) .finally(() => setLoading(false)); }, [serverUuid, revision.id]); return (
e.stopPropagation()}>
Diff — Revision #{revision.revision_number}
{loading &&
Loading diff…
} {!loading && binary &&
Binary file — diff not available.
} {!loading && !binary && (
                        {lines.map((line, i) => (
                            
{line.line_old ?? ' '} {line.line_new ?? ' '} {line.type === 'added' ? '+' : line.type === 'removed' ? '−' : ' '} {line.content}
))}
)}
); }