import React, { useState } from "react"; import { Icon } from "./icon"; interface CommitDialogProps { isOpen: boolean; filePath: string; originalContent: string; newContent: string; onCommit: (message: string) => Promise; onCancel: () => void; } export const CommitDialog: React.FC = ({ isOpen, filePath, originalContent, newContent, onCommit, onCancel, }) => { const [message, setMessage] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(">"); if (!isOpen) return null; const generateDiff = () => { const originalLines = originalContent.split("\n"); const newLines = newContent.split("\n"); const maxLines = Math.max(originalLines.length, newLines.length); const diff: { type: "same" | "added" | "removed"; line: string; lineNum: number }[] = []; for (let i = 0; i < maxLines; i++) { const original = originalLines[i] || ""; const updated = newLines[i] || ""; if (original === updated) { diff.push({ type: "same", line: updated, lineNum: i + 1 }); } else { if (original) { diff.push({ type: "removed", line: original, lineNum: i + 1 }); } if (updated) { diff.push({ type: "added", line: updated, lineNum: i + 1 }); } } } return diff; }; const handleCommit = async () => { if (!message.trim()) { setError("Please enter a commit message"); return; } setLoading(true); setError(""); try { await onCommit(message); } catch { setError("Failed to commit changes"); } finally { setLoading(false); } }; const diff = generateDiff(); const hasChanges = diff.some((d) => d.type !== "same"); return (

Commit Changes

Editing: {filePath}

{!hasChanges && (
No changes to commit
)} {hasChanges && (

Changes

{diff.map((line, i) => (
{line.lineNum} {line.type === "added" && "+"} {line.type === "removed" && "-"} {line.type === "same" && " "} {line.line}
))}
)}