import { useAtomValue } from "jotai"; import React, { useRef, useState } from "react"; import { Link } from "react-router"; import { calcCodeSize, gamingLeftTimeSecondsAtom, scoreAtom, statusAtom, } from "../../states/play"; import type { PlayerProfile } from "../../types/PlayerProfile"; import type { SupportedLanguage } from "../../types/SupportedLanguage"; import BorderedContainer from "../BorderedContainer"; import LeftTime from "../Gaming/LeftTime"; import ProblemColumn from "../Gaming/ProblemColumn"; import SubmitButton from "../SubmitButton"; import SubmitStatusLabel from "../SubmitStatusLabel"; import ThreeColumnLayout from "../ThreeColumnLayout"; import TitledColumn from "../TitledColumn"; import UserIcon from "../UserIcon"; type Props = { gameDisplayName: string; playerProfile: PlayerProfile; problemTitle: string; problemDescription: string; problemLanguage: SupportedLanguage; sampleCode: string; initialCode: string; onCodeChange: (code: string) => void; onCodeSubmit: (code: string) => void; isFinished: boolean; }; export default function GolfPlayAppGaming({ gameDisplayName, playerProfile, problemTitle, problemDescription, problemLanguage, sampleCode, initialCode, onCodeChange, onCodeSubmit, isFinished, }: Props) { const leftTimeSeconds = useAtomValue(gamingLeftTimeSecondsAtom)!; const score = useAtomValue(scoreAtom); const status = useAtomValue(statusAtom); const [codeSize, setCodeSize] = useState( calcCodeSize(initialCode, problemLanguage), ); const textareaRef = useRef(null); const handleTextChange = (e: React.ChangeEvent) => { setCodeSize(calcCodeSize(e.target.value, problemLanguage)); if (!isFinished) { onCodeChange(e.target.value); } }; const handleSubmitButtonClick = () => { if (textareaRef.current && !isFinished) { onCodeSubmit(textareaRef.current.value); } }; return (
{gameDisplayName}
{isFinished ? (
終了
) : ( )}
{score}
{playerProfile.displayName}
{playerProfile.iconPath && ( )}
コードサイズ: {codeSize}
提出