From 7a4171d021a709e0af1e0e13830514c67ec97702 Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
Date: Sat, 3 Aug 2024 22:18:31 +0900
Subject: feat: partially implement submit action

---
 .../components/GolfPlayApps/GolfPlayAppGaming.tsx  | 27 +++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

(limited to 'frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx')

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>
-- 
cgit v1.3.1

