Skip to content

Commit

Permalink
refactor: quiz view
Browse files Browse the repository at this point in the history
  • Loading branch information
rabyeoljji committed Dec 21, 2024
1 parent 3a9fdfd commit f40df7c
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 156 deletions.
17 changes: 5 additions & 12 deletions src/app/(routes)/profile/today-quiz/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,16 @@ import InviteReward from '@/features/payment/components/invite-reward'
import Icon from '@/shared/components/custom/icon'
import Text from '@/shared/components/ui/text'
import { getTodayQuizInfo } from '@/requests/quiz/server'
import { todayQuizCheckList } from '@/features/quiz/config'

const TodayQuizPage = async () => {
const { currentConsecutiveDays } = await getTodayQuizInfo()

const defaultCheckData = [
{ day: 1, isComplete: false },
{ day: 2, isComplete: false },
{ day: 3, isComplete: false },
{ day: 4, isComplete: false },
{ day: 5, isComplete: false },
]

const todayCheckData = defaultCheckData.map((checkItem) => {
if (checkItem.day > currentConsecutiveDays) {
return { ...checkItem }
const todayCheckData = todayQuizCheckList.map((checkItem) => {
if (checkItem.day <= currentConsecutiveDays) {
return { ...checkItem, isComplete: true }
}
return { ...checkItem, isComplete: true }
return { ...checkItem }
})

return (
Expand Down
15 changes: 5 additions & 10 deletions src/features/quiz/components/replay-quiz-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,13 @@ const ReplayQuizDrawer = ({
{
onSuccess: (data) =>
router.push(
'/quiz/' +
data.quizSetId +
'?quizSetType=DOCUMENT_QUIZ_SET' +
`/quiz/${data.quizSetId}?` +
'quizSetType=DOCUMENT_QUIZ_SET' +
'&' +
'createdAt=' +
data.createdAt +
`createdAt=${data.createdAt}&documentName=${documentName}&directoryEmoji=${directoryEmoji}` +
'&' +
'documentName=' +
documentName +
'&' +
'directoryEmoji=' +
directoryEmoji
'redirectUrl=' +
`/document/${documentId}`
),
}
)
Expand Down
8 changes: 8 additions & 0 deletions src/features/quiz/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,11 @@ export const reportOptions = [

export const QUIZ_ANIMATION_DURATION = 1
export const UNTIL_EXPLANATION_DRAWER_OPEN = 800

export const todayQuizCheckList = [
{ day: 1, isComplete: false },
{ day: 2, isComplete: false },
{ day: 3, isComplete: false },
{ day: 4, isComplete: false },
{ day: 5, isComplete: false },
]
12 changes: 5 additions & 7 deletions src/features/quiz/screen/ai-creating-quiz/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@ const AiCreatingQuiz = ({ documentId, documentName, directoryEmoji, onError }: P
createCheckQuizSetMutate(documentId, {
onSuccess: (data) => {
router.push(
'/quiz/' +
data.quizSetId +
'?quizSetType=FIRST_QUIZ_SET' +
`/quiz/${data.quizSetId}?` +
'quizSetType=FIRST_QUIZ_SET' +
'&' +
`createdAt=${data.createdAt}` +
`createdAt=${data.createdAt}&documentName=${documentName}&directoryEmoji=${directoryEmoji}` +
'&' +
`documentName=${documentName}` +
'&' +
`directoryEmoji=${directoryEmoji}`
'redirectUrl=' +
`/document/${documentId}`
)
},
})
Expand Down
144 changes: 144 additions & 0 deletions src/features/quiz/screen/quiz-result/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import Icon from '@/shared/components/custom/icon'
import Text from '@/shared/components/ui/text'
import { msToElapsedTimeKorean } from '@/shared/utils/time'
import { QuizItem } from '@/types/quiz'
import QuizCard from '../../components/quiz-card'
import { Button } from '@/shared/components/ui/button'
import FixedBottom from '@/shared/components/custom/fixed-bottom'

interface Props {
collectQuizCount: number
quizzes: QuizItem[]
totalElapsedTime: number
showRecord: boolean
setShowRecord: (value: boolean) => void
quizResults: ({
id: number
answer: NonNullable<boolean | undefined>
choseAnswer: string
elapsedTime: number
} | null)[]
onClick: () => void
}

const QuizResult = ({
collectQuizCount,
quizzes,
totalElapsedTime,
showRecord,
setShowRecord,
quizResults,
onClick,
}: Props) => {
return (
<div className="min-h-dvh bg-background-base-02 px-4 pb-[100px]">
<div className="translate-y-[15vh] pb-[140px]">
<div className="relative w-full rounded-[20px] bg-white">
<Icon name="complete-quiz" className="absolute right-1/2 top-[-58px] translate-x-1/2" />
<div className="pt-[98px] text-center">
<Text typography="subtitle1-bold">퀴즈 완료!</Text>
<Text typography="hero" className="mt-1">
<span className="text-text-info">{collectQuizCount}</span>/{quizzes.length}
</Text>
</div>

<div className="flex justify-between px-[40px] pb-[29px] pt-[48px]">
<div className="flex flex-col items-center">
<div className="flex-center size-10">
<Icon name="speech-bubble-color" />
</div>
<Text typography="text2-medium" color="sub" className="mt-2">
문제 수
</Text>
<Text typography="subtitle2-bold" className="mt-0.5">
{quizzes.length} 문제
</Text>
</div>

<div className="h-[90px] w-px self-center bg-[#EAECEF]" />

<div className="flex flex-col items-center">
<div className="flex-center size-10">
<Icon name="timer-color" />
</div>
<Text typography="text2-medium" color="sub" className="mt-2">
소요시간
</Text>
<Text typography="subtitle2-bold" className="mt-0.5">
{msToElapsedTimeKorean(totalElapsedTime)}
</Text>
</div>

<div className="h-[90px] w-px self-center bg-[#EAECEF]" />

<div className="flex flex-col items-center">
<div className="flex-center size-10">
<Icon name="correct-check-round" />
</div>
<Text typography="text2-medium" color="sub" className="mt-2">
정답률
</Text>
<Text typography="subtitle2-bold" className="mt-0.5">
{Math.floor((collectQuizCount / quizzes.length) * 100)}%
</Text>
</div>
</div>
</div>

{showRecord ? (
<div className="mt-[49px]">
<Text typography="title3">
{quizzes.length}문제 중 <span className="text-text-info">{collectQuizCount}문제</span>{' '}
맞았어요
</Text>
<div className="mt-5 flex flex-col gap-3">
{quizzes.map((quiz, index) => (
<QuizCard
key={quiz.id}
quiz={quiz}
header={
<div className="flex items-center justify-between">
<Text typography="text1-bold">
{quizResults[index]?.answer ? (
<span className="text-text-success">정답</span>
) : (
<span className="text-text-critical">오답</span>
)}
</Text>
<Text typography="text2-medium" color="caption">
전공 공부 {'>'} 최근 이슈
</Text>
</div>
}
userAnswer={quizResults[index]?.choseAnswer}
answerMode={true}
showExplanation={true}
/>
))}
</div>
</div>
) : (
<div>
<Button
variant="mediumSquare"
colors="tertiary"
className="mt-4 flex w-full items-center gap-2 text-button2"
onClick={() => setShowRecord(true)}
>
<span>기록 보기</span>
<Icon name="chevron-down" className="size-[16px] text-icon-tertiary" />
</Button>
</div>
)}
</div>

<FixedBottom>
<Button className="w-full" onClick={onClick}>
확인
</Button>
</FixedBottom>
</div>
)
}

export default QuizResult
Loading

0 comments on commit f40df7c

Please sign in to comment.