import { useAtomValue } from "jotai"; import React, { useRef, useState } from "react"; import { Link } from "react-router"; import { gamingLeftTimeSecondsAtom, scoreAtom, statusAtom, } from "../../states/play"; import type { PlayerProfile } from "../../types/PlayerProfile"; import BorderedContainer from "../BorderedContainer"; import LeftTime from "../Gaming/LeftTime"; import Problem from "../Gaming/Problem"; import SubmitButton from "../SubmitButton"; import SubmitStatusLabel from "../SubmitStatusLabel"; import ThreeColumnLayout from "../ThreeColumnLayout"; import UserIcon from "../UserIcon"; function calcCodeSize(code: string): number { const trimmed = code .replace(/\s+/g, "") .replace(/^<\?php/, "") .replace(/^<\?/, "") .replace(/\?>$/, ""); const utf8Encoded = new TextEncoder().encode(trimmed); return utf8Encoded.length; } type Props = { gameDisplayName: string; playerProfile: PlayerProfile; problemTitle: string; problemDescription: string; sampleCode: string; initialCode: string; onCodeChange: (code: string) => void; onCodeSubmit: (code: string) => void; }; export default function GolfPlayAppGaming({ gameDisplayName, playerProfile, problemTitle, problemDescription, sampleCode, initialCode, onCodeChange, onCodeSubmit, }: Props) { const leftTimeSeconds = useAtomValue(gamingLeftTimeSecondsAtom)!; 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); }; const handleSubmitButtonClick = () => { if (textareaRef.current) { onCodeSubmit(textareaRef.current.value); } }; return (
{gameDisplayName}
{score}
Player 1
{playerProfile.displayName}
{playerProfile.iconPath && ( )}
ソースコード
コードサイズ: {codeSize}
提出