forked from accordproject/template-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffModal.tsx
More file actions
79 lines (71 loc) · 1.65 KB
/
DiffModal.tsx
File metadata and controls
79 lines (71 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Modal, Button, Typography } from "antd";
import styled from "styled-components";
const { Text, Paragraph } = Typography;
const DiffContainer = styled.pre`
background-color: #f5f5f5;
padding: 10px;
border-radius: 4px;
max-height: 300px;
overflow-y: auto;
font-family: monospace;
white-space: pre-wrap;
.removed {
background-color: #ffdddd;
color: #b30000;
}
.added {
background-color: #ddffdd;
color: #006600;
}
`;
interface DiffModalProps {
isOpen: boolean;
onClose: () => void;
onAccept: () => void;
diff: string;
explanation: string;
}
export function DiffModal({ isOpen, onClose, onAccept, diff, explanation }: DiffModalProps) {
const formattedDiff = diff.split("\n").map((line, index) => {
if (line.startsWith("+")) {
return (
<div key={index} className="added">
{line}
</div>
);
} else if (line.startsWith("-")) {
return (
<div key={index} className="removed">
{line}
</div>
);
}
return <div key={index}>{line}</div>;
});
return (
<Modal
title="Review AI Changes"
open={isOpen}
onCancel={onClose}
footer={[
<Button key="back" onClick={onClose}>
Cancel
</Button>,
<Button key="submit" type="primary" onClick={onAccept}>
Accept Changes
</Button>,
]}
width={700}
>
{explanation && (
<Paragraph>
<Text strong>Explanation:</Text>
<br />
{explanation}
</Paragraph>
)}
<Text strong>Changes:</Text>
<DiffContainer>{formattedDiff}</DiffContainer>
</Modal>
);
}