import { useAtomValue } from "jotai"; import React, { useRef, useState } from "react"; import { Link } from "wouter"; import type { components } from "../../api/schema"; 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 CodePopover from "../Gaming/CodePopover"; import DataTable, { DataTableCell, formatUnixTimestamp, } from "../Gaming/DataTable"; 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 Submission = components["schemas"]["Submission"]; 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; submissions: Submission[]; }; export default function GolfPlayAppGaming({ gameDisplayName, playerProfile, problemTitle, problemDescription, problemLanguage, sampleCode, initialCode, onCodeChange, onCodeSubmit, isFinished, submissions, }: 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 ? (
終了
) : leftTimeSeconds === null ? (
未開始
) : ( )}
{score}
{playerProfile.displayName}
{playerProfile.iconPath && ( )}
コードサイズ: {codeSize}
提出