학습 내용 선택 화면 추가

This commit is contained in:
2026-05-29 22:48:23 +09:00
parent 4d6fb49cba
commit 335898b721
8 changed files with 495 additions and 82 deletions
@@ -0,0 +1,142 @@
"use client";
import Link from "next/link";
import { useEffect, useRef } from "react";
import { useGameStore } from "@/store/gameStore";
import type { ProblemCount } from "@/store/gameStore";
const problemCounts: ProblemCount[] = [5, 10];
const bracketKinds = [
{
label: "()",
name: "소괄호",
selected: true,
disabled: false,
},
{
label: "{}",
name: "중괄호",
selected: false,
disabled: true,
},
{
label: "[]",
name: "대괄호",
selected: false,
disabled: true,
},
];
export default function NumberParenthesesClient() {
const startLinkRef = useRef<HTMLAnchorElement>(null);
const selectedProblemCount = useGameStore(
(state) => state.selectedProblemCount,
);
const setProblemCount = useGameStore((state) => state.setProblemCount);
const initSession = useGameStore((state) => state.initSession);
useEffect(() => {
startLinkRef.current?.focus();
}, []);
return (
<main className="flex min-h-screen items-center bg-slate-50 px-6 py-12 text-slate-950">
<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">
</p>
<h1 className="text-4xl font-bold tracking-normal sm:text-5xl">
</h1>
<p className="max-w-2xl text-lg leading-8 text-slate-700">
.
</p>
</div>
<div className="flex flex-col gap-6">
<fieldset className="space-y-3">
<legend className="text-sm font-semibold text-slate-700">
</legend>
<div
className="inline-flex gap-1 rounded-md border border-slate-300 bg-white p-1 shadow-sm"
role="group"
aria-label="문제 수 선택"
>
{problemCounts.map((count) => {
const selected = selectedProblemCount === count;
return (
<button
key={count}
type="button"
onClick={() => setProblemCount(count)}
aria-pressed={selected}
className={`h-10 min-w-16 rounded px-4 text-base font-semibold transition focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 ${
selected
? "bg-emerald-700 text-white"
: "text-slate-700 hover:bg-slate-100"
}`}
>
{count}
</button>
);
})}
</div>
</fieldset>
<fieldset className="space-y-3">
<legend className="text-sm font-semibold text-slate-700">
</legend>
<div
className="inline-flex gap-1 rounded-md border border-slate-300 bg-white p-1 shadow-sm"
role="group"
aria-label="괄호 종류 선택"
>
{bracketKinds.map((bracketKind) => (
<button
key={bracketKind.label}
type="button"
disabled={bracketKind.disabled}
aria-pressed={bracketKind.selected}
aria-label={`${bracketKind.name} ${bracketKind.disabled ? "준비 중" : "선택됨"}`}
className={`h-10 min-w-16 rounded px-4 text-base font-semibold transition focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 ${
bracketKind.selected
? "bg-emerald-700 text-white"
: "text-slate-700 hover:bg-slate-100"
} ${
bracketKind.disabled
? "cursor-not-allowed bg-slate-100 text-slate-400 hover:bg-slate-100"
: ""
}`}
>
{bracketKind.label}
</button>
))}
</div>
</fieldset>
<div>
<Link
ref={startLinkRef}
href={`/play?count=${selectedProblemCount}`}
onClick={() => initSession(selectedProblemCount)}
className="inline-flex h-12 items-center justify-center rounded-md bg-emerald-700 px-6 text-base font-semibold text-white transition hover:bg-emerald-800 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2"
>
</Link>
</div>
</div>
<div className="border-l-4 border-emerald-700 pl-4 text-sm leading-6 text-slate-600">
<p> .</p>
</div>
</section>
</main>
);
}
+5
View File
@@ -0,0 +1,5 @@
import NumberParenthesesClient from "./NumberParenthesesClient";
export default function NumberParenthesesPage() {
return <NumberParenthesesClient />;
}
+2 -2
View File
@@ -121,7 +121,7 @@ export default function PlayClient({ problemCount }: PlayClientProps) {
const rect = katexElement.getBoundingClientRect();
const scrollElement =
document.scrollingElement ?? document.documentElement;
const elementDocumentTop = window.pageYOffset + rect.top;
const elementDocumentTop = window.scrollY + rect.top;
const maxScrollTop = Math.max(
0,
scrollElement.scrollHeight - window.innerHeight,
@@ -131,7 +131,7 @@ export default function PlayClient({ problemCount }: PlayClientProps) {
Math.max(0, elementDocumentTop),
);
if (Math.abs(window.pageYOffset - scrollTop) < 4) return;
if (Math.abs(window.scrollY - scrollTop) < 4) return;
scrollElement.scrollTop = scrollTop;
document.body.scrollTop = scrollTop;