From ab6abc3a7619be89dda1bc3ab0b3f19ff69b575f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 12 Aug 2024 01:54:36 +0900 Subject: refactor(frontend): rename SubmissionResult and VerificationResult for consistant naming --- .../app/components/ExecStatusIndicatorIcon.tsx | 4 +- frontend/app/components/GolfWatchApp.client.tsx | 51 +++++++++--------- .../GolfWatchApps/GolfWatchAppGaming.tsx | 62 ++++++++++------------ frontend/app/models/ExecResult.ts | 17 ++++++ frontend/app/models/PlayerInfo.ts | 4 +- frontend/app/models/SubmissionResult.ts | 38 ------------- frontend/app/models/SubmitResult.ts | 36 +++++++++++++ frontend/app/models/VerificationResult.ts | 17 ------ 8 files changed, 111 insertions(+), 118 deletions(-) create mode 100644 frontend/app/models/ExecResult.ts delete mode 100644 frontend/app/models/SubmissionResult.ts create mode 100644 frontend/app/models/SubmitResult.ts delete mode 100644 frontend/app/models/VerificationResult.ts diff --git a/frontend/app/components/ExecStatusIndicatorIcon.tsx b/frontend/app/components/ExecStatusIndicatorIcon.tsx index c5b37f8..b5c53ec 100644 --- a/frontend/app/components/ExecStatusIndicatorIcon.tsx +++ b/frontend/app/components/ExecStatusIndicatorIcon.tsx @@ -5,10 +5,10 @@ import { faRotate, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { VerificationResultStatus } from "../models/VerificationResult"; +import { ExecResultStatus } from "../models/ExecResult"; type Props = { - status: VerificationResultStatus; + status: ExecResultStatus; }; export default function ExecStatusIndicatorIcon({ status }: Props) { diff --git a/frontend/app/components/GolfWatchApp.client.tsx b/frontend/app/components/GolfWatchApp.client.tsx index 3f97d2a..7041572 100644 --- a/frontend/app/components/GolfWatchApp.client.tsx +++ b/frontend/app/components/GolfWatchApp.client.tsx @@ -78,14 +78,14 @@ export default function GolfWatchApp({ iconPath: playerA?.icon_path ?? null, score: null, code: "", - submissionResult: undefined, + submitResult: undefined, }); const [playerInfoB, setPlayerInfoB] = useState({ displayName: playerB?.display_name ?? null, iconPath: playerB?.icon_path ?? null, score: null, code: "", - submissionResult: undefined, + submitResult: undefined, }); if (readyState === ReadyState.UNINSTANTIATED) { @@ -125,12 +125,12 @@ export default function GolfWatchApp({ player_id === playerA?.user_id ? setPlayerInfoA : setPlayerInfoB; setter((prev) => ({ ...prev, - submissionResult: { + submitResult: { status: "running", - verificationResults: game.verification_steps.map((v) => ({ - testcase_id: v.testcase_id, + execResults: game.verification_steps.map((r) => ({ + testcase_id: r.testcase_id, status: "running", - label: v.label, + label: r.label, stdout: "", stderr: "", })), @@ -143,21 +143,20 @@ export default function GolfWatchApp({ player_id === playerA?.user_id ? setPlayerInfoA : setPlayerInfoB; setter((prev) => { const ret = { ...prev }; - if (ret.submissionResult === undefined) { + if (ret.submitResult === undefined) { return ret; } - ret.submissionResult = { - ...ret.submissionResult, - verificationResults: ret.submissionResult.verificationResults.map( - (v) => - v.testcase_id === testcase_id && v.status === "running" - ? { - ...v, - status, - stdout, - stderr, - } - : v, + ret.submitResult = { + ...ret.submitResult, + execResults: ret.submitResult.execResults.map((r) => + r.testcase_id === testcase_id && r.status === "running" + ? { + ...r, + status, + stdout, + stderr, + } + : r, ), }; return ret; @@ -168,11 +167,11 @@ export default function GolfWatchApp({ player_id === playerA?.user_id ? setPlayerInfoA : setPlayerInfoB; setter((prev) => { const ret = { ...prev }; - if (ret.submissionResult === undefined) { + if (ret.submitResult === undefined) { return ret; } - ret.submissionResult = { - ...ret.submissionResult, + ret.submitResult = { + ...ret.submitResult, status, }; if (status === "success") { @@ -182,10 +181,10 @@ export default function GolfWatchApp({ } } } else { - ret.submissionResult.verificationResults = - ret.submissionResult.verificationResults.map((v) => - v.status === "running" ? { ...v, status: "canceled" } : v, - ); + ret.submitResult.execResults = ret.submitResult.execResults.map( + (r) => + r.status === "running" ? { ...r, status: "canceled" } : r, + ); } return ret; }); diff --git a/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx b/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx index 5ca778b..bdd1ac3 100644 --- a/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx +++ b/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx @@ -1,5 +1,5 @@ import { PlayerInfo } from "../../models/PlayerInfo"; -import { submissionResultStatusToLabel } from "../../models/SubmissionResult"; +import { submitResultStatusToLabel } from "../../models/SubmitResult"; import ExecStatusIndicatorIcon from "../ExecStatusIndicatorIcon"; type Props = { @@ -60,28 +60,26 @@ export default function GolfWatchAppGaming({
- {submissionResultStatusToLabel( - playerInfoA.submissionResult?.status ?? null, + {submitResultStatusToLabel( + playerInfoA.submitResult?.status ?? null, )}
    - {playerInfoA.submissionResult?.verificationResults.map( - (result) => ( -
  1. + {playerInfoA.submitResult?.execResults.map((result) => ( +
  2. +
    -
    - {" "} - {result.label} -
    -
    - {result.stdout} - {result.stderr} -
    + {" "} + {result.label}
    -
  3. - ), - )} +
    + {result.stdout} + {result.stderr} +
    +
+ + ))}
@@ -92,28 +90,26 @@ export default function GolfWatchAppGaming({
- {submissionResultStatusToLabel( - playerInfoB.submissionResult?.status ?? null, + {submitResultStatusToLabel( + playerInfoB.submitResult?.status ?? null, )}
    - {playerInfoB.submissionResult?.verificationResults.map( - (result, idx) => ( -
  1. + {playerInfoB.submitResult?.execResults.map((result, idx) => ( +
  2. +
    +
    + {" "} + {result.label} +
    -
    - {" "} - {result.label} -
    -
    - {result.stdout} - {result.stderr} -
    + {result.stdout} + {result.stderr}
    -
  3. - ), - )} +
+ + ))}
diff --git a/frontend/app/models/ExecResult.ts b/frontend/app/models/ExecResult.ts new file mode 100644 index 0000000..59b8ee8 --- /dev/null +++ b/frontend/app/models/ExecResult.ts @@ -0,0 +1,17 @@ +export type ExecResultStatus = + | "running" + | "success" + | "wrong_answer" + | "timeout" + | "compile_error" + | "runtime_error" + | "internal_error" + | "canceled"; + +export type ExecResult = { + testcase_id: number | null; + status: ExecResultStatus; + label: string; + stdout: string; + stderr: string; +}; diff --git a/frontend/app/models/PlayerInfo.ts b/frontend/app/models/PlayerInfo.ts index 7206a8b..30cccea 100644 --- a/frontend/app/models/PlayerInfo.ts +++ b/frontend/app/models/PlayerInfo.ts @@ -1,9 +1,9 @@ -import type { SubmissionResult } from "./SubmissionResult"; +import type { SubmitResult } from "./SubmitResult"; export type PlayerInfo = { displayName: string | null; iconPath: string | null; score: number | null; code: string | null; - submissionResult?: SubmissionResult; + submitResult?: SubmitResult; }; diff --git a/frontend/app/models/SubmissionResult.ts b/frontend/app/models/SubmissionResult.ts deleted file mode 100644 index 7311494..0000000 --- a/frontend/app/models/SubmissionResult.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { VerificationResult } from "./VerificationResult"; - -export type SubmissionResultStatus = - | "running" - | "success" - | "wrong_answer" - | "timeout" - | "compile_error" - | "runtime_error" - | "internal_error"; - -export type SubmissionResult = { - status: SubmissionResultStatus; - verificationResults: VerificationResult[]; -}; - -export function submissionResultStatusToLabel( - status: SubmissionResultStatus | null, -) { - switch (status) { - case null: - return "-"; - case "running": - return "Running..."; - case "success": - return "Accepted"; - case "wrong_answer": - return "Wrong Answer"; - case "timeout": - return "Time Limit Exceeded"; - case "compile_error": - return "Compile Error"; - case "runtime_error": - return "Runtime Error"; - case "internal_error": - return "Internal Error"; - } -} diff --git a/frontend/app/models/SubmitResult.ts b/frontend/app/models/SubmitResult.ts new file mode 100644 index 0000000..403a0db --- /dev/null +++ b/frontend/app/models/SubmitResult.ts @@ -0,0 +1,36 @@ +import type { ExecResult } from "./ExecResult"; + +export type SubmitResultStatus = + | "running" + | "success" + | "wrong_answer" + | "timeout" + | "compile_error" + | "runtime_error" + | "internal_error"; + +export type SubmitResult = { + status: SubmitResultStatus; + execResults: ExecResult[]; +}; + +export function submitResultStatusToLabel(status: SubmitResultStatus | null) { + switch (status) { + case null: + return "-"; + case "running": + return "Running..."; + case "success": + return "Accepted"; + case "wrong_answer": + return "Wrong Answer"; + case "timeout": + return "Time Limit Exceeded"; + case "compile_error": + return "Compile Error"; + case "runtime_error": + return "Runtime Error"; + case "internal_error": + return "Internal Error"; + } +} diff --git a/frontend/app/models/VerificationResult.ts b/frontend/app/models/VerificationResult.ts deleted file mode 100644 index 09a7ef4..0000000 --- a/frontend/app/models/VerificationResult.ts +++ /dev/null @@ -1,17 +0,0 @@ -export type VerificationResultStatus = - | "running" - | "success" - | "wrong_answer" - | "timeout" - | "compile_error" - | "runtime_error" - | "internal_error" - | "canceled"; - -export type VerificationResult = { - testcase_id: number | null; - status: VerificationResultStatus; - label: string; - stdout: string; - stderr: string; -}; -- cgit v1.2.3-70-g09d2