mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 07:16:34 +00:00
chore(toast): rename show-exit-code-toast.tsx to show-status-toast.tsx
This commit is contained in:
parent
5e3b75a36b
commit
6e22822383
@ -11,8 +11,8 @@ import { useState } from "react";
|
|||||||
import { judge } from "@/actions/judge";
|
import { judge } from "@/actions/judge";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { useProblem } from "@/hooks/use-problem";
|
import { useProblem } from "@/hooks/use-problem";
|
||||||
|
import { showStatusToast } from "@/lib/show-status-toast";
|
||||||
import { LoaderCircleIcon, PlayIcon } from "lucide-react";
|
import { LoaderCircleIcon, PlayIcon } from "lucide-react";
|
||||||
import { showExitCodeToast } from "@/lib/show-exit-code-toast";
|
|
||||||
|
|
||||||
interface RunCodeProps {
|
interface RunCodeProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
@ -33,7 +33,7 @@ export function RunCode({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await judge(currentLang, code, problemId);
|
const result = await judge(currentLang, code, problemId);
|
||||||
showExitCodeToast({ exitCode: result.exitCode });
|
showStatusToast({ status: result.status });
|
||||||
} 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);
|
||||||
|
@ -6,24 +6,28 @@ import {
|
|||||||
XIcon,
|
XIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { ExitCode } from "@/generated/client";
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import type { Status } from "@/generated/client";
|
||||||
|
|
||||||
const getColorClass = (code: ExitCode) => {
|
const getColorClass = (code: Status) => {
|
||||||
const colorMap: Record<ExitCode, string> = {
|
const colorMap: Record<Status, string> = {
|
||||||
SE: "text-red-500",
|
PD: "text-gray-400",
|
||||||
CS: "text-green-500",
|
QD: "text-gray-400",
|
||||||
|
CP: "text-yellow-400",
|
||||||
CE: "text-yellow-500",
|
CE: "text-yellow-500",
|
||||||
|
CS: "text-green-500",
|
||||||
|
RU: "text-blue-400",
|
||||||
TLE: "text-blue-500",
|
TLE: "text-blue-500",
|
||||||
MLE: "text-purple-500",
|
MLE: "text-purple-500",
|
||||||
RE: "text-orange-500",
|
RE: "text-orange-500",
|
||||||
AC: "text-green-500",
|
AC: "text-green-500",
|
||||||
WA: "text-red-500",
|
WA: "text-red-500",
|
||||||
|
SE: "text-red-500",
|
||||||
};
|
};
|
||||||
return colorMap[code] || "text-gray-500";
|
return colorMap[code] || "text-gray-500";
|
||||||
};
|
};
|
||||||
|
|
||||||
const exitCodeMap = new Map<ExitCode, { icon: LucideIcon; message: string }>([
|
const statusMap = new Map<Status, { icon: LucideIcon; message: string }>([
|
||||||
["SE", { icon: BanIcon, message: "System Error" }],
|
["SE", { icon: BanIcon, message: "System Error" }],
|
||||||
["CS", { icon: CircleCheckIcon, message: "Compilation Success" }],
|
["CS", { icon: CircleCheckIcon, message: "Compilation Success" }],
|
||||||
["CE", { icon: AlertTriangleIcon, message: "Compilation Error" }],
|
["CE", { icon: AlertTriangleIcon, message: "Compilation Error" }],
|
||||||
@ -34,7 +38,7 @@ const exitCodeMap = new Map<ExitCode, { icon: LucideIcon; message: string }>([
|
|||||||
["WA", { icon: AlertTriangleIcon, message: "Wrong Answer" }],
|
["WA", { icon: AlertTriangleIcon, message: "Wrong Answer" }],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const ExitCodeToast = ({
|
const StatusToast = ({
|
||||||
t,
|
t,
|
||||||
Icon,
|
Icon,
|
||||||
message,
|
message,
|
||||||
@ -76,21 +80,21 @@ const ExitCodeToast = ({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
interface ShowExitCodeToastProps {
|
interface ShowStatusToastProps {
|
||||||
exitCode: ExitCode;
|
status: Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showExitCodeToast({
|
export function showStatusToast({
|
||||||
exitCode,
|
status,
|
||||||
}: ShowExitCodeToastProps) {
|
}: ShowStatusToastProps) {
|
||||||
const { icon: Icon, message } = exitCodeMap.get(exitCode) || {
|
const { icon: Icon, message } = statusMap.get(status) || {
|
||||||
icon: XIcon,
|
icon: XIcon,
|
||||||
message: "Unknown Error",
|
message: "Unknown Error",
|
||||||
};
|
};
|
||||||
const colorClass = getColorClass(exitCode);
|
const colorClass = getColorClass(status);
|
||||||
|
|
||||||
toast.custom((t) => (
|
toast.custom((t) => (
|
||||||
<ExitCodeToast
|
<StatusToast
|
||||||
t={t}
|
t={t}
|
||||||
Icon={Icon}
|
Icon={Icon}
|
||||||
message={message}
|
message={message}
|
Loading…
Reference in New Issue
Block a user