From 6e2282238385e81b1d28d3f25087b0c29a07fa73 Mon Sep 17 00:00:00 2001 From: cfngc4594 Date: Thu, 10 Apr 2025 22:42:41 +0800 Subject: [PATCH] chore(toast): rename show-exit-code-toast.tsx to show-status-toast.tsx --- src/components/run-code.tsx | 4 +-- ...t-code-toast.tsx => show-status-toast.tsx} | 34 +++++++++++-------- 2 files changed, 21 insertions(+), 17 deletions(-) rename src/lib/{show-exit-code-toast.tsx => show-status-toast.tsx} (79%) diff --git a/src/components/run-code.tsx b/src/components/run-code.tsx index b22821e..ab9ceb9 100644 --- a/src/components/run-code.tsx +++ b/src/components/run-code.tsx @@ -11,8 +11,8 @@ import { useState } from "react"; import { judge } from "@/actions/judge"; import { Button } from "@/components/ui/button"; import { useProblem } from "@/hooks/use-problem"; +import { showStatusToast } from "@/lib/show-status-toast"; import { LoaderCircleIcon, PlayIcon } from "lucide-react"; -import { showExitCodeToast } from "@/lib/show-exit-code-toast"; interface RunCodeProps { className?: string; @@ -33,7 +33,7 @@ export function RunCode({ try { const result = await judge(currentLang, code, problemId); - showExitCodeToast({ exitCode: result.exitCode }); + showStatusToast({ status: result.status }); } catch (error) { console.error("Error occurred while judging the code:"); console.error(error); diff --git a/src/lib/show-exit-code-toast.tsx b/src/lib/show-status-toast.tsx similarity index 79% rename from src/lib/show-exit-code-toast.tsx rename to src/lib/show-status-toast.tsx index 1cbea3c..e540162 100644 --- a/src/lib/show-exit-code-toast.tsx +++ b/src/lib/show-status-toast.tsx @@ -6,24 +6,28 @@ import { XIcon, } from "lucide-react"; import { toast } from "sonner"; -import { ExitCode } from "@/generated/client"; import { Button } from "@/components/ui/button"; +import type { Status } from "@/generated/client"; -const getColorClass = (code: ExitCode) => { - const colorMap: Record = { - SE: "text-red-500", - CS: "text-green-500", +const getColorClass = (code: Status) => { + const colorMap: Record = { + PD: "text-gray-400", + QD: "text-gray-400", + CP: "text-yellow-400", CE: "text-yellow-500", + CS: "text-green-500", + RU: "text-blue-400", TLE: "text-blue-500", MLE: "text-purple-500", RE: "text-orange-500", AC: "text-green-500", WA: "text-red-500", + SE: "text-red-500", }; return colorMap[code] || "text-gray-500"; }; -const exitCodeMap = new Map([ +const statusMap = new Map([ ["SE", { icon: BanIcon, message: "System Error" }], ["CS", { icon: CircleCheckIcon, message: "Compilation Success" }], ["CE", { icon: AlertTriangleIcon, message: "Compilation Error" }], @@ -34,7 +38,7 @@ const exitCodeMap = new Map([ ["WA", { icon: AlertTriangleIcon, message: "Wrong Answer" }], ]); -const ExitCodeToast = ({ +const StatusToast = ({ t, Icon, message, @@ -76,21 +80,21 @@ const ExitCodeToast = ({ ); -interface ShowExitCodeToastProps { - exitCode: ExitCode; +interface ShowStatusToastProps { + status: Status; } -export function showExitCodeToast({ - exitCode, -}: ShowExitCodeToastProps) { - const { icon: Icon, message } = exitCodeMap.get(exitCode) || { +export function showStatusToast({ + status, +}: ShowStatusToastProps) { + const { icon: Icon, message } = statusMap.get(status) || { icon: XIcon, message: "Unknown Error", }; - const colorClass = getColorClass(exitCode); + const colorClass = getColorClass(status); toast.custom((t) => ( -