diff --git a/src/components/run-code.tsx b/src/components/run-code.tsx index 6e4af52..d1b920c 100644 --- a/src/components/run-code.tsx +++ b/src/components/run-code.tsx @@ -1,6 +1,11 @@ +"use client"; + import { cn } from "@/lib/utils"; -import { PlayIcon } from "lucide-react"; +import { useState } from "react"; +import { judge } from "@/app/actions/judge"; import { Button } from "@/components/ui/button"; +import { LoaderCircleIcon, PlayIcon } from "lucide-react"; +import { useCodeEditorState } from "@/store/useCodeEditor"; interface RunCodeProps { className?: string; @@ -10,14 +15,44 @@ export default function RunCode({ className, ...props }: RunCodeProps) { + const { language, editor } = useCodeEditorState(); + const [isLoading, setIsLoading] = useState(false); + + const handleJudge = async () => { + if (!editor) return; + + const code = editor.getValue() || ""; + setIsLoading(true); + + try { + const judgeResult = await judge(language, code); + console.log(judgeResult); + } catch (error) { + console.error("Error occurred while judging the code:"); + console.error(error); + } finally { + setIsLoading(false); + } + }; + return ( ); }