리펙토링: 코드 최적화
This commit is contained in:
@@ -38,13 +38,13 @@ export default function PlayClient({ problemCount }: PlayClientProps) {
|
||||
const [answerB, setAnswerB] = useState("");
|
||||
const [inputError, setInputError] = useState("");
|
||||
|
||||
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 =
|
||||
session === null || session.problems.length !== problemCount;
|
||||
const sessionNeedsInit = sessionProblemCount !== problemCount;
|
||||
const correctCount =
|
||||
session?.results.filter((result) => result?.correct).length ?? 0;
|
||||
const totalCount = session?.problems.length ?? 0;
|
||||
@@ -61,7 +61,7 @@ export default function PlayClient({ problemCount }: PlayClientProps) {
|
||||
initSession,
|
||||
problemCount,
|
||||
selectedProblemCount,
|
||||
session,
|
||||
sessionProblemCount,
|
||||
sessionNeedsInit,
|
||||
setProblemCount,
|
||||
]);
|
||||
@@ -89,7 +89,7 @@ export default function PlayClient({ problemCount }: PlayClientProps) {
|
||||
submitAnswer({ a: parsedA, b: parsedB });
|
||||
}
|
||||
|
||||
if (sessionNeedsInit) {
|
||||
if (!session || sessionNeedsInit) {
|
||||
return (
|
||||
<main className="flex min-h-screen items-center bg-slate-50 px-6 py-12 text-slate-950">
|
||||
<section className="mx-auto w-full max-w-3xl">
|
||||
|
||||
@@ -3,11 +3,15 @@ import type { ProblemCount } from "@/store/gameStore";
|
||||
|
||||
interface PlayPageProps {
|
||||
searchParams?: {
|
||||
count?: string;
|
||||
count?: string | string[];
|
||||
};
|
||||
}
|
||||
|
||||
function parseProblemCount(count?: string): ProblemCount {
|
||||
function parseProblemCount(count?: string | string[]): ProblemCount {
|
||||
if (Array.isArray(count)) {
|
||||
return parseProblemCount(count[0]);
|
||||
}
|
||||
|
||||
return count === "5" ? 5 : 10;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ export default function Home() {
|
||||
<section className="mx-auto flex w-full max-w-3xl flex-col gap-8">
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm font-semibold text-emerald-700">
|
||||
중학교 2학년 수학 실수 유형 연습
|
||||
중학교 2학년 수학 - 괄호 풀기 연습
|
||||
</p>
|
||||
<h1 className="text-4xl font-bold tracking-normal sm:text-5xl">
|
||||
괄호 음수 분배 연습
|
||||
|
||||
Reference in New Issue
Block a user