From ad42f43d1c3c8f0da0ac31b8016e2f20f1765720 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 18 Aug 2024 00:38:07 +0900 Subject: refactor(frontend): extract components for gaming page --- .../app/components/ExecStatusIndicatorIcon.tsx | 51 --------- frontend/app/components/Gaming/CodeBlock.tsx | 11 ++ .../components/Gaming/ExecStatusIndicatorIcon.tsx | 51 +++++++++ frontend/app/components/Gaming/ScoreBar.tsx | 25 +++++ frontend/app/components/Gaming/SubmitResult.tsx | 56 ++++++++++ .../components/GolfPlayApps/GolfPlayAppGaming.tsx | 52 ++------- .../GolfWatchApps/GolfWatchAppGaming.tsx | 120 +++------------------ 7 files changed, 168 insertions(+), 198 deletions(-) delete mode 100644 frontend/app/components/ExecStatusIndicatorIcon.tsx create mode 100644 frontend/app/components/Gaming/CodeBlock.tsx create mode 100644 frontend/app/components/Gaming/ExecStatusIndicatorIcon.tsx create mode 100644 frontend/app/components/Gaming/ScoreBar.tsx create mode 100644 frontend/app/components/Gaming/SubmitResult.tsx (limited to 'frontend') diff --git a/frontend/app/components/ExecStatusIndicatorIcon.tsx b/frontend/app/components/ExecStatusIndicatorIcon.tsx deleted file mode 100644 index 5277bfa..0000000 --- a/frontend/app/components/ExecStatusIndicatorIcon.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { - faBan, - faCircle, - faCircleCheck, - faCircleExclamation, - faRotate, -} from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import type { ExecResultStatus } from "../models/ExecResult"; - -type Props = { - status: ExecResultStatus; -}; - -export default function ExecStatusIndicatorIcon({ status }: Props) { - switch (status) { - case "waiting_submission": - return ( - - ); - case "running": - return ( - - ); - case "success": - return ( - - ); - case "canceled": - return ( - - ); - default: - return ( - - ); - } -} diff --git a/frontend/app/components/Gaming/CodeBlock.tsx b/frontend/app/components/Gaming/CodeBlock.tsx new file mode 100644 index 0000000..20cd425 --- /dev/null +++ b/frontend/app/components/Gaming/CodeBlock.tsx @@ -0,0 +1,11 @@ +type Props = { + code: string; +}; + +export default function CodeBlock({ code }: Props) { + return ( +
+			{code}
+		
+ ); +} diff --git a/frontend/app/components/Gaming/ExecStatusIndicatorIcon.tsx b/frontend/app/components/Gaming/ExecStatusIndicatorIcon.tsx new file mode 100644 index 0000000..8daf48c --- /dev/null +++ b/frontend/app/components/Gaming/ExecStatusIndicatorIcon.tsx @@ -0,0 +1,51 @@ +import { + faBan, + faCircle, + faCircleCheck, + faCircleExclamation, + faRotate, +} from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import type { ExecResultStatus } from "../../models/ExecResult"; + +type Props = { + status: ExecResultStatus; +}; + +export default function ExecStatusIndicatorIcon({ status }: Props) { + switch (status) { + case "waiting_submission": + return ( + + ); + case "running": + return ( + + ); + case "success": + return ( + + ); + case "canceled": + return ( + + ); + default: + return ( + + ); + } +} diff --git a/frontend/app/components/Gaming/ScoreBar.tsx b/frontend/app/components/Gaming/ScoreBar.tsx new file mode 100644 index 0000000..4eac3ad --- /dev/null +++ b/frontend/app/components/Gaming/ScoreBar.tsx @@ -0,0 +1,25 @@ +type Props = { + scoreA: number | null; + scoreB: number | null; + bgA: string; + bgB: string; +}; + +export default function ScoreBar({ scoreA, scoreB, bgA, bgB }: Props) { + let scoreRatio; + if (scoreA === null && scoreB === null) { + scoreRatio = 50; + } else if (scoreA === null) { + scoreRatio = 0; + } else if (scoreB === null) { + scoreRatio = 100; + } else { + scoreRatio = (scoreB / (scoreA + scoreB)) * 100; + } + + return ( +
+
+
+ ); +} diff --git a/frontend/app/components/Gaming/SubmitResult.tsx b/frontend/app/components/Gaming/SubmitResult.tsx new file mode 100644 index 0000000..ae83e92 --- /dev/null +++ b/frontend/app/components/Gaming/SubmitResult.tsx @@ -0,0 +1,56 @@ +import { faArrowDown } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import React from "react"; +import type { SubmitResult } from "../../models/SubmitResult"; +import BorderedContainer from "../BorderedContainer"; +import SubmitStatusLabel from "../SubmitStatusLabel"; +import ExecStatusIndicatorIcon from "./ExecStatusIndicatorIcon"; + +type Props = { + result: SubmitResult; + submitButton?: React.ReactNode; +}; + +export default function SubmitResult({ result, submitButton }: Props) { + return ( +
+
+ {submitButton} +
+ +
+
+
    + {result.execResults.map((r, idx) => ( +
  • +
    +
    + +
    + {idx !== result.execResults.length - 1 && ( +
    + +
    + )} +
    +
    + +
    {r.label}
    +
    + + {r.stdout} + {r.stderr} + +
    +
    +
    +
  • + ))} +
+
+ ); +} diff --git a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx index a6c4550..e9139ba 100644 --- a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx +++ b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx @@ -1,12 +1,9 @@ -import { faArrowDown } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Link } from "@remix-run/react"; import React, { useRef } from "react"; import SubmitButton from "../../components/SubmitButton"; import type { PlayerInfo } from "../../models/PlayerInfo"; import BorderedContainer from "../BorderedContainer"; -import ExecStatusIndicatorIcon from "../ExecStatusIndicatorIcon"; -import SubmitStatusLabel from "../SubmitStatusLabel"; +import SubmitResult from "../Gaming/SubmitResult"; type Props = { gameDisplayName: string; @@ -92,44 +89,15 @@ export default function GolfPlayAppGaming({ className="resize-none h-full w-full rounded-lg border border-gray-300 p-2 focus:outline-none focus:ring-2 focus:ring-gray-400 transition duration-300" > -
-
- 提出 -
- -
-
-
    - {playerInfo.submitResult.execResults.map((r, idx) => ( -
  • -
    -
    - -
    - {idx !== playerInfo.submitResult.execResults.length - 1 && ( -
    - -
    - )} -
    -
    - -
    {r.label}
    -
    - - {r.stdout} - {r.stderr} - -
    -
    -
    -
  • - ))} -
+
+ + 提出 + + } + />
diff --git a/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx b/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx index 63c232b..d17c2dc 100644 --- a/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx +++ b/frontend/app/components/GolfWatchApps/GolfWatchAppGaming.tsx @@ -1,9 +1,7 @@ -import { faArrowDown } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { PlayerInfo } from "../../models/PlayerInfo"; -import BorderedContainer from "../BorderedContainer"; -import ExecStatusIndicatorIcon from "../ExecStatusIndicatorIcon"; -import SubmitStatusLabel from "../SubmitStatusLabel"; +import CodeBlock from "../Gaming/CodeBlock"; +import ScoreBar from "../Gaming/ScoreBar"; +import SubmitResult from "../Gaming/SubmitResult"; type Props = { gameDisplayName: string; @@ -29,20 +27,6 @@ export default function GolfWatchAppGaming({ return `${m.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`; })(); - const scoreRatio = (() => { - const scoreA = playerInfoA.score; - const scoreB = playerInfoB.score; - if (scoreA === null && scoreB === null) { - return 50; - } else if (scoreA === null) { - return 0; - } else if (scoreB === null) { - return 100; - } else { - return (scoreB / (scoreA + scoreB)) * 100; - } - })(); - return (
@@ -91,98 +75,24 @@ export default function GolfWatchAppGaming({
-
-
-
+
-
-						{playerInfoA.code}
-					
+
-
-
-
- -
-
-
    - {playerInfoA.submitResult.execResults.map((r, idx) => ( -
  • -
    -
    - -
    - {idx !== playerInfoA.submitResult.execResults.length - 1 && ( -
    - -
    - )} -
    -
    - -
    {r.label}
    -
    - - {r.stdout} - {r.stderr} - -
    -
    -
    -
  • - ))} -
+
+
-
-
-
- -
-
-
    - {playerInfoB.submitResult.execResults.map((r, idx) => ( -
  • -
    -
    - -
    - {idx !== playerInfoB.submitResult.execResults.length - 1 && ( -
    - -
    - )} -
    -
    - -
    {r.label}
    -
    - - {r.stdout} - {r.stderr} - -
    -
    -
    -
  • - ))} -
+
+
-
-						{playerInfoB.code}
-					
+
-- cgit v1.2.3-70-g09d2