-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 여러 문제를 관리하는 상태 추가 * feat: 메인 페이지 UI 구현 * feat: 메인 페이지 기능 추가 - 버튼 클릭 시 핀번호 검사 후 이동 - 엔터 버튼 클릭 시 검사 --------- Co-authored-by: dooohun <[email protected]>
- Loading branch information
1 parent
777cf14
commit 205e000
Showing
5 changed files
with
220 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { toastController } from '@/features/toast/model/toastController'; | ||
import { useState } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
const useGetPinNumbers = () => { | ||
return { data: [123456] }; | ||
}; | ||
|
||
export default function MainPage() { | ||
const [pin, setPin] = useState<string>(''); | ||
const { data: pinNumbers } = useGetPinNumbers(); | ||
|
||
const naviagte = useNavigate(); | ||
const toast = toastController(); | ||
|
||
const handleClick = () => { | ||
if (pinNumbers?.includes(Number(pin))) { | ||
naviagte('nickname'); | ||
return; | ||
} | ||
toast.error('유효하지 않은 코드입니다'); | ||
}; | ||
|
||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === 'Enter') { | ||
handleClick(); | ||
} | ||
}; | ||
return ( | ||
<section className="min-h-screen flex flex-col items-center"> | ||
<h1 className="text-6xl font-bold text-primary mt-32 mb-24">You Quiz</h1> | ||
|
||
<div className="w-full max-w-4xl px-4"> | ||
<div className="w-full flex justify-between border-[1.5px] border-primary rounded-xl p-2"> | ||
<input | ||
type="text" | ||
placeholder="Join Code" | ||
className="w-3/4 border-none outline-none p-3 bg-transparent" | ||
value={pin} | ||
onChange={(e) => setPin(e.target.value)} | ||
onKeyDown={handleKeyDown} | ||
/> | ||
<button | ||
className="bg-primary text-white text-md font-semibold rounded-xl py-2 px-6" | ||
onClick={handleClick} | ||
> | ||
퀴즈 참가하기 | ||
</button> | ||
</div> | ||
</div> | ||
|
||
<div className="mt-4"> | ||
<button className="px-6 py-2 text-primary border border-weak rounded-full hover:bg-primary-light"> | ||
로그인 | ||
</button> | ||
<button className="px-6 py-2 text-primary border border-weak rounded-full hover:bg-primary-light"> | ||
회원가입 | ||
</button> | ||
</div> | ||
</section> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,115 @@ | ||
import { useState } from 'react'; | ||
|
||
import { CustomButton } from '@/shared/ui/buttons'; | ||
import PlusIcon from '@/shared/assets/icons/plus.svg?react'; | ||
import QuizCreateSection from './ui/QuizCreateSection'; | ||
|
||
interface Choice { | ||
content: string; | ||
isCorrect: boolean; | ||
position: number; | ||
} | ||
|
||
export interface QuizData { | ||
content: string; | ||
quizType: 'MC' | 'TF'; | ||
timeLimit: number; | ||
point: number; | ||
position: number; | ||
choices: Choice[]; | ||
} | ||
|
||
export default function QuizCreatePage() { | ||
//TODO: 문제 추가하기 상태 관리 | ||
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 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 }, | ||
], | ||
}, | ||
]); | ||
setCurrentQuizIndex((prev) => prev + 1); | ||
}; | ||
|
||
const handlePreQuiz = () => { | ||
if (currentQuizIndex === 0) return; | ||
setCurrentQuizIndex((prev) => prev - 1); | ||
}; | ||
|
||
const handleNextQuiz = () => { | ||
if (currentQuizIndex === quizzes.length - 1) return; | ||
setCurrentQuizIndex((prev) => prev + 1); | ||
}; | ||
|
||
return ( | ||
<div className="flex w-full"> | ||
<QuizCreateSection /> | ||
<div className="flex flex-col w-full mt-6 mr-6"> | ||
<div className=" flex gap-4 bg-white rounded-base p-4 mb-4"> | ||
<button className="text-weak-md" onClick={handlePreQuiz}> | ||
이전 문제 | ||
</button> | ||
<button className="text-weak-md" onClick={handleNextQuiz}> | ||
다음 문제 | ||
</button> | ||
<div className="flex-1 flex justify-end text-weak-md">문제 유형</div> | ||
</div> | ||
|
||
<QuizCreateSection | ||
key={currentQuizIndex} | ||
currentQuizIndex={currentQuizIndex} | ||
quizData={quizzes[currentQuizIndex]} | ||
onQuizUpdate={(updatedData) => { | ||
setQuizzes((prev) => { | ||
const newQuizzes = [...prev]; | ||
newQuizzes[currentQuizIndex] = updatedData as QuizData; | ||
return newQuizzes; | ||
}); | ||
}} | ||
/> | ||
|
||
<div className="self-start mt-10"> | ||
<CustomButton | ||
Icon={PlusIcon} | ||
type="outline" | ||
size="md" | ||
color="primary" | ||
label="문제 추가하기" | ||
onClick={() => { | ||
addNewQuiz(); | ||
console.log(quizzes); | ||
console.log(currentQuizIndex); | ||
}} | ||
/> | ||
</div> | ||
<div className="self-end mr-6"> | ||
<CustomButton | ||
label="퀴즈 발행하기" | ||
onClick={() => { | ||
console.log('퀴즈 발행하기'); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters