"use client"; import Link from "next/link"; import { useEffect, useState } from "react"; import { flushSync } from "react-dom"; import StageIndicator from "@/components/game/StageIndicator"; import VariableChoiceAnswerForm from "@/components/game/VariableChoiceAnswerForm"; import VariableFeedbackPanel from "@/components/game/VariableFeedbackPanel"; import VariableScoreSummary from "@/components/game/VariableScoreSummary"; import KatexRenderer from "@/components/math/KatexRenderer"; import { useVariableGameStore, type VariableProblemCount, } from "@/store/variableGameStore"; interface VariablePlayClientProps { problemCount: VariableProblemCount; } export default function VariablePlayClient({ problemCount, }: VariablePlayClientProps) { const session = useVariableGameStore((state) => state.session); const selectedProblemCount = useVariableGameStore( (state) => state.selectedProblemCount, ); const setProblemCount = useVariableGameStore( (state) => state.setProblemCount, ); const initSession = useVariableGameStore((state) => state.initSession); const submitAnswer = useVariableGameStore((state) => state.submitAnswer); const nextProblem = useVariableGameStore((state) => state.nextProblem); const resetSession = useVariableGameStore((state) => state.resetSession); const [selectedChoiceIds, setSelectedChoiceIds] = useState< [string | null, string | null] >([null, null]); const [activeTermIndex, setActiveTermIndex] = useState<0 | 1>(0); const sessionProblemCount = session?.problems.length ?? null; const currentProblem = session?.problems[session.currentIndex] ?? null; const currentResult = session?.results[session.currentIndex] ?? null; const isComplete = Boolean( session && session.currentIndex >= session.problems.length, ); const sessionNeedsInit = sessionProblemCount !== problemCount; const correctCount = session?.results.filter((result) => result?.correct).length ?? 0; const totalCount = session?.problems.length ?? 0; useEffect(() => { if (selectedProblemCount !== problemCount) { setProblemCount(problemCount); } if (sessionNeedsInit) { initSession(problemCount); } }, [ initSession, problemCount, selectedProblemCount, sessionProblemCount, sessionNeedsInit, setProblemCount, ]); useEffect(() => { setSelectedChoiceIds([null, null]); setActiveTermIndex(0); }, [currentProblem?.key]); function handleSelectChoice(termIndex: 0 | 1, choiceId: string) { setSelectedChoiceIds((current) => { const next: [string | null, string | null] = [...current]; next[termIndex] = choiceId; return next; }); if (termIndex === 0) { setActiveTermIndex(1); } } function handleSubmit() { if (currentResult || !currentProblem) return; if (selectedChoiceIds[0] === null || selectedChoiceIds[1] === null) return; submitAnswer({ selectedChoiceIds }); } function handleNextProblem() { flushSync(() => { nextProblem(); }); } if (!session || sessionNeedsInit) { return ( 문제를 준비하고 있습니다. ); } if (isComplete) { return ( ); } if (!currentProblem) { return ( 현재 문제를 불러올 수 없습니다. ); } const submitted = currentResult !== null; const isLastProblem = session.currentIndex === session.problems.length - 1; return ( 미지수 괄호 풀기 문제 풀이 포기 괄호를 풀어 첫째 항과 둘째 항의 답을 보기에서 고르세요. {!submitted ? ( ) : null} {currentResult ? ( ) : null} ); }
문제를 준비하고 있습니다.
현재 문제를 불러올 수 없습니다.
미지수 괄호 풀기
괄호를 풀어 첫째 항과 둘째 항의 답을 보기에서 고르세요.