Skip to content

Commit

Permalink
[FE - #36] 퀴즈 생성 페이지 수정 (#56)
Browse files Browse the repository at this point in the history
* feat: 여러 문제를 관리하는 상태 추가

* fix: 수정사항 반영

- 초기값 변수로 선언해두고 활용
- 타입 단언 제거
  • Loading branch information
chan-byeong authored Nov 14, 2024
1 parent 205e000 commit 46bfc11
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
45 changes: 16 additions & 29 deletions packages/FE/src/pages/quiz-create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<QuizData[]>([
{
content: '',
quizType: 'MC',
timeLimit: 30,
point: 1000,
position: 0,
choices: [
{ content: '', isCorrect: false, position: 0 },
{ content: '', isCorrect: false, position: 1 },
],
},
]);
const [quizzes, setQuizzes] = useState<QuizData[]>([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);
};

Expand Down Expand Up @@ -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;
});
}}
Expand Down
2 changes: 1 addition & 1 deletion packages/FE/src/pages/quiz-create/ui/QuizCreateSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { QuizData } from '../index';
interface QuizCreateSectionProps {
quizData: QuizData;
currentQuizIndex: number;
onQuizUpdate: (updatedData: Partial<QuizData>) => void;
onQuizUpdate: (updatedData: QuizData) => void;
}

export default function QuizCreateSection({
Expand Down

0 comments on commit 46bfc11

Please sign in to comment.