Skip to content

Commit 3740018

Browse files
feat: add DiffApprovalDialog component
1 parent 323488d commit 3740018

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { useStore } from '@nanostores/react';
2+
import { useState } from 'react';
3+
import * as RadixDialog from '@radix-ui/react-dialog';
4+
import { workbenchStore } from '~/lib/stores/workbench';
5+
import { InlineDiffComparison } from './DiffView';
6+
import { Dialog, DialogTitle } from '~/components/ui/Dialog';
7+
import { Button } from '~/components/ui/Button';
8+
9+
export function DiffApprovalDialog() {
10+
const pending = useStore(workbenchStore.pendingApproval);
11+
const [isApproving, setIsApproving] = useState(false);
12+
13+
if (!pending) {
14+
return null;
15+
}
16+
17+
const { filePath, beforeContent, afterContent } = pending;
18+
19+
const getLanguageFromPath = (path: string) => {
20+
const ext = path.split('.').pop()?.toLowerCase() || '';
21+
const langMap: Record<string, string> = {
22+
ts: 'typescript',
23+
tsx: 'tsx',
24+
js: 'javascript',
25+
jsx: 'jsx',
26+
json: 'json',
27+
html: 'html',
28+
css: 'css',
29+
py: 'python',
30+
php: 'php',
31+
java: 'java',
32+
c: 'c',
33+
cpp: 'cpp',
34+
cs: 'csharp',
35+
go: 'go',
36+
rb: 'ruby',
37+
rs: 'rust',
38+
};
39+
40+
return langMap[ext] || 'plaintext';
41+
};
42+
43+
const handleApprove = async () => {
44+
setIsApproving(true);
45+
46+
try {
47+
await workbenchStore.approveFileChange();
48+
} finally {
49+
setIsApproving(false);
50+
}
51+
};
52+
53+
const handleReject = async () => {
54+
await workbenchStore.rejectFileChange();
55+
};
56+
57+
const language = getLanguageFromPath(filePath);
58+
59+
return (
60+
<RadixDialog.Root open={true}>
61+
<Dialog showCloseButton={false}>
62+
<div className="flex flex-col h-full max-h-[80vh]">
63+
<div className="p-6 border-b border-codinit-elements-borderColor">
64+
<DialogTitle>Approve File Change</DialogTitle>
65+
<div className="mt-2 text-sm text-codinit-elements-textSecondary font-mono">{filePath}</div>
66+
</div>
67+
68+
<div className="flex-1 overflow-hidden">
69+
<InlineDiffComparison
70+
beforeCode={beforeContent}
71+
afterCode={afterContent}
72+
language={language}
73+
filename={filePath}
74+
lightTheme="github-light"
75+
darkTheme="github-dark"
76+
/>
77+
</div>
78+
79+
<div className="p-6 border-t border-codinit-elements-borderColor bg-codinit-elements-background-depth-2 flex justify-end gap-3">
80+
<Button variant="outline" onClick={handleReject} disabled={isApproving}>
81+
Reject
82+
</Button>
83+
<Button
84+
variant="default"
85+
onClick={handleApprove}
86+
disabled={isApproving}
87+
className="bg-green-600 hover:bg-green-700 text-white"
88+
>
89+
{isApproving ? (
90+
<>
91+
<div className="i-ph-spinner-gap-bold animate-spin w-4 h-4 mr-2" />
92+
Approving...
93+
</>
94+
) : (
95+
'Approve'
96+
)}
97+
</Button>
98+
</div>
99+
</div>
100+
</Dialog>
101+
</RadixDialog.Root>
102+
);
103+
}

0 commit comments

Comments
 (0)