mirror of
https://github.com/cfngc4594/monaco-editor-lsp-next.git
synced 2025-05-18 15:26:36 +00:00
refactor(status): extract status logic into separate module
- Moved color class and status map logic to `src/lib/status.ts` - Simplified `showStatusToast` and `StatusToast` components - Replaced `getColorClass` with `getStatusColorClass` from the new module
This commit is contained in:
parent
31441aed89
commit
ad43eb9b0a
@ -1,42 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
AlertTriangleIcon,
|
|
||||||
BanIcon,
|
|
||||||
CircleCheckIcon,
|
|
||||||
LucideIcon,
|
LucideIcon,
|
||||||
XIcon,
|
XIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import type { Status } from "@/generated/client";
|
import type { Status } from "@/generated/client";
|
||||||
|
import { getStatusColorClass, statusMap } from "@/lib/status";
|
||||||
const getColorClass = (code: Status) => {
|
|
||||||
const colorMap: Record<Status, string> = {
|
|
||||||
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 statusMap = new Map<Status, { icon: LucideIcon; message: string }>([
|
|
||||||
["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 StatusToast = ({
|
const StatusToast = ({
|
||||||
t,
|
t,
|
||||||
@ -88,7 +57,7 @@ export function showStatusToast({
|
|||||||
icon: XIcon,
|
icon: XIcon,
|
||||||
message: "Unknown Error",
|
message: "Unknown Error",
|
||||||
};
|
};
|
||||||
const colorClass = getColorClass(status);
|
const colorClass = getStatusColorClass(status);
|
||||||
|
|
||||||
toast.custom((t) => (
|
toast.custom((t) => (
|
||||||
<StatusToast
|
<StatusToast
|
||||||
@ -97,9 +66,5 @@ export function showStatusToast({
|
|||||||
message={message}
|
message={message}
|
||||||
colorClass={colorClass}
|
colorClass={colorClass}
|
||||||
/>
|
/>
|
||||||
),
|
));
|
||||||
{
|
|
||||||
duration: Infinity,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
40
src/lib/status.ts
Normal file
40
src/lib/status.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import {
|
||||||
|
AlertTriangleIcon,
|
||||||
|
BanIcon,
|
||||||
|
CircleCheckIcon,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { LucideIcon } from "lucide-react";
|
||||||
|
import { Status } from "@/generated/client";
|
||||||
|
|
||||||
|
export const getStatusColorClass = (status: Status) => {
|
||||||
|
const colorMap: Record<Status, string> = {
|
||||||
|
PD: "text-gray-500",
|
||||||
|
QD: "text-gray-500",
|
||||||
|
CP: "text-yellow-500",
|
||||||
|
CE: "text-yellow-500",
|
||||||
|
CS: "text-green-500",
|
||||||
|
RU: "text-blue-500",
|
||||||
|
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[status] || "text-gray-500";
|
||||||
|
};
|
||||||
|
|
||||||
|
export const statusMap = new Map<Status, { icon: LucideIcon; message: string }>([
|
||||||
|
["PD", { icon: AlertTriangleIcon, message: "Pending" }],
|
||||||
|
["QD", { icon: AlertTriangleIcon, message: "Queued" }],
|
||||||
|
["CP", { icon: AlertTriangleIcon, message: "Compiling" }],
|
||||||
|
["CE", { icon: AlertTriangleIcon, message: "Compilation Error" }],
|
||||||
|
["CS", { icon: CircleCheckIcon, message: "Compilation Success" }],
|
||||||
|
["RU", { icon: AlertTriangleIcon, message: "Running" }],
|
||||||
|
["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" }],
|
||||||
|
["SE", { icon: BanIcon, message: "System Error" }],
|
||||||
|
]);
|
Loading…
Reference in New Issue
Block a user