diff --git a/src/lib/show-exit-code-toast.tsx b/src/lib/show-exit-code-toast.tsx new file mode 100644 index 0000000..2e4cd7c --- /dev/null +++ b/src/lib/show-exit-code-toast.tsx @@ -0,0 +1,100 @@ +import { + AlertTriangleIcon, + BanIcon, + CircleCheckIcon, + LucideIcon, + XIcon, +} from "lucide-react"; +import { toast } from "sonner"; +import { ExitCode } from "@prisma/client"; +import { Button } from "@/components/ui/button"; + +const getColorClass = (code: ExitCode) => { + const colorMap: Record = { + SE: "text-red-500", + CS: "text-green-500", + CE: "text-yellow-500", + TLE: "text-blue-500", + MLE: "text-purple-500", + RE: "text-orange-500", + AC: "text-green-500", + WA: "text-red-500", + }; + return colorMap[code] || "text-gray-500"; +}; + +const exitCodeMap = new Map([ + ["SE", { icon: BanIcon, message: "System Error" }], + ["CS", { icon: CircleCheckIcon, message: "Compilation Success" }], + ["CE", { icon: AlertTriangleIcon, message: "Compilation Error" }], + ["TLE", { icon: AlertTriangleIcon, message: "Time Limit Exceeded" }], + ["MLE", { icon: AlertTriangleIcon, message: "Memory Limit Exceeded" }], + ["RE", { icon: AlertTriangleIcon, message: "Runtime Error" }], + ["AC", { icon: CircleCheckIcon, message: "Accepted" }], + ["WA", { icon: AlertTriangleIcon, message: "Wrong Answer" }], +]); + +const ExitCodeToast = ({ + t, + Icon, + message, + colorClass, +}: { + t: string | number; + Icon: LucideIcon; + message: string; + colorClass: string; +}) => ( +
+
+
+
+ +
+
+); + +interface ShowExitCodeToastProps { + exitCode: ExitCode; +} + +export function showExitCodeToast({ + exitCode, +}: ShowExitCodeToastProps) { + const { icon: Icon, message } = exitCodeMap.get(exitCode) || { + icon: XIcon, + message: "Unknown Error", + }; + const colorClass = getColorClass(exitCode); + + toast.custom((t) => ( + + )); +}