From 7a4171d021a709e0af1e0e13830514c67ec97702 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 3 Aug 2024 22:18:31 +0900 Subject: feat: partially implement submit action --- frontend/app/.server/api/schema.d.ts | 11 ++++++++- frontend/app/components/GolfPlayApp.client.tsx | 9 ++++++++ .../components/GolfPlayApps/GolfPlayAppGaming.tsx | 27 +++++++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-) (limited to 'frontend') diff --git a/frontend/app/.server/api/schema.d.ts b/frontend/app/.server/api/schema.d.ts index 705380d..1c8cead 100644 --- a/frontend/app/.server/api/schema.d.ts +++ b/frontend/app/.server/api/schema.d.ts @@ -201,7 +201,7 @@ export interface components { /** @example 100 */ score: number | null; }; - GamePlayerMessageC2S: components["schemas"]["GamePlayerMessageC2SEntry"] | components["schemas"]["GamePlayerMessageC2SReady"] | components["schemas"]["GamePlayerMessageC2SCode"]; + GamePlayerMessageC2S: components["schemas"]["GamePlayerMessageC2SEntry"] | components["schemas"]["GamePlayerMessageC2SReady"] | components["schemas"]["GamePlayerMessageC2SCode"] | components["schemas"]["GamePlayerMessageC2SSubmit"]; GamePlayerMessageC2SEntry: { /** @constant */ type: "player:c2s:entry"; @@ -219,6 +219,15 @@ export interface components { /** @example print('Hello, world!') */ code: string; }; + GamePlayerMessageC2SSubmit: { + /** @constant */ + type: "player:c2s:submit"; + data: components["schemas"]["GamePlayerMessageC2SSubmitPayload"]; + }; + GamePlayerMessageC2SSubmitPayload: { + /** @example print('Hello, world!') */ + code: string; + }; GameWatcherMessage: components["schemas"]["GameWatcherMessageS2C"]; GameWatcherMessageS2C: components["schemas"]["GameWatcherMessageS2CStart"] | components["schemas"]["GameWatcherMessageS2CCode"] | components["schemas"]["GameWatcherMessageS2CExecResult"]; GameWatcherMessageS2CStart: { diff --git a/frontend/app/components/GolfPlayApp.client.tsx b/frontend/app/components/GolfPlayApp.client.tsx index ace0710..80e7182 100644 --- a/frontend/app/components/GolfPlayApp.client.tsx +++ b/frontend/app/components/GolfPlayApp.client.tsx @@ -81,6 +81,14 @@ export default function GolfPlayApp({ }); }, 1000); + const onCodeSubmit = useDebouncedCallback((code: string) => { + console.log("player:c2s:submit"); + sendJsonMessage({ + type: "player:c2s:submit", + data: { code }, + }); + }, 1000); + if (readyState === ReadyState.UNINSTANTIATED) { throw new Error("WebSocket is not connected"); } @@ -140,6 +148,7 @@ export default function GolfPlayApp({ ); diff --git a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx index 75ab18e..9fddb01 100644 --- a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx +++ b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx @@ -1,18 +1,30 @@ +import React, { useRef } from "react"; + type Props = { problem: string; onCodeChange: (code: string) => void; + onCodeSubmit: (code: string) => void; currentScore: number | null; }; export default function GolfPlayAppGaming({ problem, onCodeChange, + onCodeSubmit, currentScore, }: Props) { + const textareaRef = useRef(null); + const handleTextChange = (e: React.ChangeEvent) => { onCodeChange(e.target.value); }; + const handleSubmitButtonClick = () => { + if (textareaRef.current) { + onCodeSubmit(textareaRef.current.value); + } + }; + return (
@@ -22,16 +34,25 @@ export default function GolfPlayAppGaming({
{problem}
-
- Score: {currentScore == null ? "-" : `${currentScore}`} +
+
+ Score: {currentScore == null ? "-" : `${currentScore}`} +
+
-- cgit v1.2.3-70-g09d2