리펙토링: 코드 최적화

This commit is contained in:
2026-05-26 15:29:50 +09:00
parent 2779bf1b0e
commit 4a08dded14
3 changed files with 11 additions and 7 deletions
+4 -4
View File
@@ -38,13 +38,13 @@ export default function PlayClient({ problemCount }: PlayClientProps) {
const [answerB, setAnswerB] = useState(""); const [answerB, setAnswerB] = useState("");
const [inputError, setInputError] = useState(""); const [inputError, setInputError] = useState("");
const sessionProblemCount = session?.problems.length ?? null;
const currentProblem = session?.problems[session.currentIndex] ?? null; const currentProblem = session?.problems[session.currentIndex] ?? null;
const currentResult = session?.results[session.currentIndex] ?? null; const currentResult = session?.results[session.currentIndex] ?? null;
const isComplete = Boolean( const isComplete = Boolean(
session && session.currentIndex >= session.problems.length, session && session.currentIndex >= session.problems.length,
); );
const sessionNeedsInit = const sessionNeedsInit = sessionProblemCount !== problemCount;
session === null || session.problems.length !== problemCount;
const correctCount = const correctCount =
session?.results.filter((result) => result?.correct).length ?? 0; session?.results.filter((result) => result?.correct).length ?? 0;
const totalCount = session?.problems.length ?? 0; const totalCount = session?.problems.length ?? 0;
@@ -61,7 +61,7 @@ export default function PlayClient({ problemCount }: PlayClientProps) {
initSession, initSession,
problemCount, problemCount,
selectedProblemCount, selectedProblemCount,
session, sessionProblemCount,
sessionNeedsInit, sessionNeedsInit,
setProblemCount, setProblemCount,
]); ]);
@@ -89,7 +89,7 @@ export default function PlayClient({ problemCount }: PlayClientProps) {
submitAnswer({ a: parsedA, b: parsedB }); submitAnswer({ a: parsedA, b: parsedB });
} }
if (sessionNeedsInit) { if (!session || sessionNeedsInit) {
return ( return (
<main className="flex min-h-screen items-center bg-slate-50 px-6 py-12 text-slate-950"> <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"> <section className="mx-auto w-full max-w-3xl">
+6 -2
View File
@@ -3,11 +3,15 @@ import type { ProblemCount } from "@/store/gameStore";
interface PlayPageProps { interface PlayPageProps {
searchParams?: { 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; return count === "5" ? 5 : 10;
} }
+1 -1
View File
@@ -6,7 +6,7 @@ export default function Home() {
<section className="mx-auto flex w-full max-w-3xl flex-col gap-8"> <section className="mx-auto flex w-full max-w-3xl flex-col gap-8">
<div className="space-y-4"> <div className="space-y-4">
<p className="text-sm font-semibold text-emerald-700"> <p className="text-sm font-semibold text-emerald-700">
2 2 -
</p> </p>
<h1 className="text-4xl font-bold tracking-normal sm:text-5xl"> <h1 className="text-4xl font-bold tracking-normal sm:text-5xl">