From 46bfc1168074dbaaecd8d5a195fd9a8028f37a31 Mon Sep 17 00:00:00 2001 From: ByeongChan Choi <77400298+chan-byeong@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:44:39 +0900 Subject: [PATCH] =?UTF-8?q?[FE=20-=20#36]=20=ED=80=B4=EC=A6=88=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?(#56)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 여러 문제를 관리하는 상태 추가 * fix: 수정사항 반영 - 초기값 변수로 선언해두고 활용 - 타입 단언 제거 --- packages/FE/src/pages/quiz-create/index.tsx | 45 +++++++------------ .../quiz-create/ui/QuizCreateSection.tsx | 2 +- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/packages/FE/src/pages/quiz-create/index.tsx b/packages/FE/src/pages/quiz-create/index.tsx index 5c1a38ac..df63c918 100644 --- a/packages/FE/src/pages/quiz-create/index.tsx +++ b/packages/FE/src/pages/quiz-create/index.tsx @@ -19,37 +19,24 @@ export interface QuizData { choices: Choice[]; } +const INITIAL_QUIZ_VALUE: QuizData = { + content: '', + quizType: 'MC', + timeLimit: 30, + point: 1000, + position: 0, + choices: [ + { content: '', isCorrect: false, position: 0 }, + { content: '', isCorrect: false, position: 1 }, + ], +}; + export default function QuizCreatePage() { const [currentQuizIndex, setCurrentQuizIndex] = useState(0); - const [quizzes, setQuizzes] = useState([ - { - content: '', - quizType: 'MC', - timeLimit: 30, - point: 1000, - position: 0, - choices: [ - { content: '', isCorrect: false, position: 0 }, - { content: '', isCorrect: false, position: 1 }, - ], - }, - ]); + const [quizzes, setQuizzes] = useState([INITIAL_QUIZ_VALUE]); const addNewQuiz = () => { - setQuizzes((prev) => [ - ...prev, - { - content: '', - quizType: 'MC', - timeLimit: 30, - point: 1000, - position: prev.length, - choices: [ - { content: '', isCorrect: false, position: 0 }, - { content: '', isCorrect: false, position: 1 }, - ], - }, - ]); + setQuizzes((prev) => [...prev, INITIAL_QUIZ_VALUE]); setCurrentQuizIndex((prev) => prev + 1); }; @@ -79,10 +66,10 @@ export default function QuizCreatePage() { key={currentQuizIndex} currentQuizIndex={currentQuizIndex} quizData={quizzes[currentQuizIndex]} - onQuizUpdate={(updatedData) => { + onQuizUpdate={(updatedData: QuizData) => { setQuizzes((prev) => { const newQuizzes = [...prev]; - newQuizzes[currentQuizIndex] = updatedData as QuizData; + newQuizzes[currentQuizIndex] = updatedData; return newQuizzes; }); }} diff --git a/packages/FE/src/pages/quiz-create/ui/QuizCreateSection.tsx b/packages/FE/src/pages/quiz-create/ui/QuizCreateSection.tsx index a97bfb2b..a095e9c3 100644 --- a/packages/FE/src/pages/quiz-create/ui/QuizCreateSection.tsx +++ b/packages/FE/src/pages/quiz-create/ui/QuizCreateSection.tsx @@ -11,7 +11,7 @@ import { QuizData } from '../index'; interface QuizCreateSectionProps { quizData: QuizData; currentQuizIndex: number; - onQuizUpdate: (updatedData: Partial) => void; + onQuizUpdate: (updatedData: QuizData) => void; } export default function QuizCreateSection({