From 4ea5bab83311929ab5e7f055cf24a71d224fbd98 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 16 Mar 2025 00:42:54 +0900 Subject: feat(frontend): show the current code size --- frontend/app/components/BorderedContainer.tsx | 7 +++- frontend/app/components/Gaming/SubmitResult.tsx | 5 +-- .../components/GolfPlayApps/GolfPlayAppGaming.tsx | 46 +++++++++++++++------- 3 files changed, 37 insertions(+), 21 deletions(-) (limited to 'frontend') diff --git a/frontend/app/components/BorderedContainer.tsx b/frontend/app/components/BorderedContainer.tsx index fe15c3b..d9b2fe8 100644 --- a/frontend/app/components/BorderedContainer.tsx +++ b/frontend/app/components/BorderedContainer.tsx @@ -2,11 +2,14 @@ import React from "react"; type Props = { children: React.ReactNode; + className?: string; }; -export default function BorderedContainer({ children }: Props) { +export default function BorderedContainer({ children, className }: Props) { return ( -
+
{children}
); diff --git a/frontend/app/components/Gaming/SubmitResult.tsx b/frontend/app/components/Gaming/SubmitResult.tsx index a78c79e..ea75b6b 100644 --- a/frontend/app/components/Gaming/SubmitResult.tsx +++ b/frontend/app/components/Gaming/SubmitResult.tsx @@ -1,17 +1,14 @@ -import React from "react"; import type { components } from "../../api/schema"; import SubmitStatusLabel from "../SubmitStatusLabel"; type Props = { status: components["schemas"]["ExecutionStatus"]; - submitButton?: React.ReactNode; }; -export default function SubmitResult({ status, submitButton }: Props) { +export default function SubmitResult({ status }: Props) { return (
- {submitButton}
diff --git a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx index 743588d..c9f9256 100644 --- a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx +++ b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx @@ -1,5 +1,5 @@ import { useAtomValue } from "jotai"; -import React, { useRef } from "react"; +import React, { useRef, useState } from "react"; import { Link } from "react-router"; import SubmitButton from "../../components/SubmitButton"; import { @@ -11,8 +11,17 @@ import type { PlayerProfile } from "../../types/PlayerProfile"; import LeftTime from "../Gaming/LeftTime"; import Problem from "../Gaming/Problem"; import SubmitResult from "../Gaming/SubmitResult"; +import BorderedContainer from "../BorderedContainer"; import UserIcon from "../UserIcon"; +function calcCodeSize(code: string): number { + return code + .replace(/\s+/g, "") + .replace(/^<\?php/, "") + .replace(/^<\?/, "") + .replace(/\?>$/, "").length; +} + type Props = { gameDisplayName: string; playerProfile: PlayerProfile; @@ -38,9 +47,11 @@ export default function GolfPlayAppGaming({ const score = useAtomValue(scoreAtom); const status = useAtomValue(statusAtom); + const [codeSize, setCodeSize] = useState(calcCodeSize(initialCode)); const textareaRef = useRef(null); const handleTextChange = (e: React.ChangeEvent) => { + setCodeSize(calcCodeSize(e.target.value)); onCodeChange(e.target.value); }; @@ -80,23 +91,28 @@ export default function GolfPlayAppGaming({ description={problemDescription} sampleCode={sampleCode} /> -
-