aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'frontend')
-rw-r--r--frontend/app/.server/api/schema.d.ts11
-rw-r--r--frontend/app/components/GolfPlayApp.client.tsx9
-rw-r--r--frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx27
3 files changed, 43 insertions, 4 deletions
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({
<GolfPlayAppGaming
problem={problem!.description}
onCodeChange={onCodeChange}
+ onCodeSubmit={onCodeSubmit}
currentScore={currentScore}
/>
);
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<HTMLTextAreaElement>(null);
+
const handleTextChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
onCodeChange(e.target.value);
};
+ const handleSubmitButtonClick = () => {
+ if (textareaRef.current) {
+ onCodeSubmit(textareaRef.current.value);
+ }
+ };
+
return (
<div className="min-h-screen flex">
<div className="mx-auto flex min-h-full flex-grow">
@@ -22,16 +34,25 @@ export default function GolfPlayAppGaming({
<div className="text-gray-700">{problem}</div>
</div>
<div className="mb-4 mt-auto">
- <div className="font-semibold text-green-500">
- Score: {currentScore == null ? "-" : `${currentScore}`}
+ <div className="mb-2">
+ <div className="font-semibold text-green-500">
+ Score: {currentScore == null ? "-" : `${currentScore}`}
+ </div>
</div>
+ <button
+ onClick={handleSubmitButtonClick}
+ className="focus:shadow-outline rounded bg-blue-500 px-4 py-2 font-bold text-white hover:bg-blue-700 focus:outline-none"
+ >
+ Submit
+ </button>
</div>
</div>
<div className="w-1/2 p-4 flex">
<div className="flex-grow">
<textarea
- className="h-full w-full rounded-lg border border-gray-300 p-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
+ ref={textareaRef}
onChange={handleTextChange}
+ className="h-full w-full rounded-lg border border-gray-300 p-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
></textarea>
</div>
</div>