mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 07:16:34 +00:00
feat(run-code): integrate exit code toast and update problem editor hook
This commit is contained in:
parent
b46a603f62
commit
69115c4ef0
@ -5,18 +5,19 @@ import { useState } from "react";
|
|||||||
import { judge } from "@/app/actions/judge";
|
import { judge } from "@/app/actions/judge";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { LoaderCircleIcon, PlayIcon } from "lucide-react";
|
import { LoaderCircleIcon, PlayIcon } from "lucide-react";
|
||||||
import { useCodeEditorStore } from "@/store/useCodeEditorStore";
|
import { useProblemEditor } from "@/hooks/use-problem-editor";
|
||||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip";
|
import { showExitCodeToast } from "@/lib/show-exit-code-toast";
|
||||||
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||||
|
|
||||||
interface RunCodeProps {
|
interface RunCodeProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function RunCode({
|
export function RunCode({
|
||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
}: RunCodeProps) {
|
}: RunCodeProps) {
|
||||||
const { language, editor, setResult } = useCodeEditorStore();
|
const { currentLang, editor } = useProblemEditor();
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
|
|
||||||
const handleJudge = async () => {
|
const handleJudge = async () => {
|
||||||
@ -26,8 +27,8 @@ export default function RunCode({
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await judge(language, code);
|
const result = await judge(currentLang, code);
|
||||||
setResult(result);
|
showExitCodeToast({ exitCode: result.exitCode });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error occurred while judging the code:");
|
console.error("Error occurred while judging the code:");
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -54,7 +55,11 @@ export default function RunCode({
|
|||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<PlayIcon className="-ms-1 opacity-60" size={16} aria-hidden="true" />
|
<PlayIcon
|
||||||
|
className="-ms-1 opacity-60"
|
||||||
|
size={16}
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{isLoading ? "Running..." : "Run"}
|
{isLoading ? "Running..." : "Run"}
|
||||||
</Button>
|
</Button>
|
||||||
|
Loading…
Reference in New Issue
Block a user