-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreview-button.tsx
More file actions
60 lines (52 loc) · 1.31 KB
/
review-button.tsx
File metadata and controls
60 lines (52 loc) · 1.31 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
"use client";
import { Button } from "@/components/ui/button";
import { api } from "@/convex/_generated/api";
import { useAction } from "convex/react";
import { Loader2 } from "lucide-react";
import { useState } from "react";
interface ReviewButtonProps {
selectedFile: string;
fileContent: string;
setReview: (review: string) => void;
}
export function ReviewButton({
selectedFile,
fileContent,
setReview,
}: ReviewButtonProps) {
const [isLoading, setIsLoading] = useState(false);
const createReviewAgent = useAction(api.agent.createCodeReviewThread);
const handleReview = async () => {
if (!selectedFile) return;
setIsLoading(true);
try {
const { text } = await createReviewAgent({
prompt:
"Please review this code and provide detailed feedback with line numbers.",
code: fileContent,
});
setReview(text);
} catch (error) {
console.error("Error creating review:", error);
} finally {
setIsLoading(false);
}
};
return (
<Button
onClick={handleReview}
disabled={isLoading}
variant="outline"
size="sm"
>
{isLoading ? (
<>
<Loader2 className='mr-2 h-4 w-4 animate-spin' />
Analyzing code...
</>
) : (
"Review File"
)}
</Button>
);
}