diff --git a/packages/client/src/pages/quiz-session/index.tsx b/packages/client/src/pages/quiz-session/index.tsx index 5c77424d..12906e95 100644 --- a/packages/client/src/pages/quiz-session/index.tsx +++ b/packages/client/src/pages/quiz-session/index.tsx @@ -1,5 +1,4 @@ import { useState, useEffect } from 'react'; -import { useParams } from 'react-router-dom'; import { getQuizSocket } from '@/shared/utils/socket'; import QuizBackground from './ui/QuizBackground'; @@ -10,23 +9,24 @@ import QuizLoading from './ui/QuizLoading'; import { toastController } from '@/features/toast/model/toastController'; export default function QuizSession() { - const { pinCode } = useParams(); const socket = getQuizSocket(); const toast = toastController(); const [isLoading, setIsLoading] = useState(true); const [isQuizEnd, setIsQuizEnd] = useState(false); - const [reactionStats, setReactionStats] = useState({ - easy: 0, - hard: 0, - }); + const [tick, setTick] = useState({ currentTime: 0, elapsedTime: 0, remainingTime: 0 }); const [quiz, setQuiz] = useState({ id: '', content: '', choices: [], }); - const totalReactions = reactionStats.easy + reactionStats.hard; - const easyPercentage = totalReactions ? (reactionStats.easy / totalReactions) * 100 : 50; + const handleTick = (response: any) => { + setTick(response); + }; + + const handleTimeEnd = () => { + setIsQuizEnd(true); + }; useEffect(() => { const quizPromise = new Promise((resolve, reject) => { @@ -62,24 +62,22 @@ export default function QuizSession() { setIsLoading(false); }); - socket.on('timer end', () => { - setIsQuizEnd(true); - }); + socket.on('timer tick', handleTick); + socket.on('time end', handleTimeEnd); return () => { - socket.off('timer end', () => {}); + socket.off('time end', handleTimeEnd); + socket.off('timer tick', handleTick); }; }, []); return ( <> - {isLoading ? ( - - ) : ( -
- - - + {isLoading && !isQuizEnd && } + {!isLoading && !isQuizEnd && ( +
+ +
)} {isQuizEnd && } diff --git a/packages/client/src/pages/quiz-session/ui/QuizBox.tsx b/packages/client/src/pages/quiz-session/ui/QuizBox.tsx index 93107732..bcd7ed18 100644 --- a/packages/client/src/pages/quiz-session/ui/QuizBox.tsx +++ b/packages/client/src/pages/quiz-session/ui/QuizBox.tsx @@ -3,25 +3,46 @@ import { Dispatch, SetStateAction, useState, useRef, useEffect, useCallback } fr import { getQuizSocket } from '@/shared/utils/socket'; import { getCookie } from '@/shared/utils/cookie'; import { useParams } from 'react-router-dom'; +import AfterQuizSubmit from './AfterQuizSubmit'; +import QuizBackground from './QuizBackground'; interface ReactionData { easy: number; hard: number; } +export interface StatisticsData { + averageTime: number; + participantRate: number; + solveRate: number; + totalSubmit: number; +} + interface QuizBoxProps { - reactionStats: ReactionData; - setReactionStats: Dispatch>; quiz: QuizData; + tick: { currentTime: number; elapsedTime: number; remainingTime: number }; } -export default function QuizBox({ reactionStats, setReactionStats, quiz }: QuizBoxProps) { +export default function QuizBox({ quiz, tick }: QuizBoxProps) { const { pinCode } = useParams(); const [selectedAnswer, setSelectedAnswer] = useState([]); const [hasSubmitted, setHasSubmitted] = useState(false); + const [reactionStats, setReactionStats] = useState({ + easy: 0, + hard: 0, + }); + const [participantStatistics, setParticipantStatistics] = useState({ + averageTime: 0, + participantRate: 0, + solveRate: 0, + totalSubmit: 0, + }); const easyButtonRef = useRef(null); const hardButtonRef = useRef(null); const socket = getQuizSocket(); - const [tick, setTick] = useState({ currentTime: 0, elapsedTime: 0, remainingTime: 0 }); + + const totalReactions = reactionStats.easy + reactionStats.hard; + const easyPercentage = totalReactions ? (reactionStats.easy / totalReactions) * 100 : 50; + const handleSelectAnswer = (idx: number) => { setSelectedAnswer((prev) => { if (prev.includes(idx)) { @@ -38,7 +59,6 @@ export default function QuizBox({ reactionStats, setReactionStats, quiz }: QuizB pinCode: pinCode, submitTime: tick.elapsedTime, }); - console.log(selectedAnswer); setHasSubmitted(true); }; @@ -65,27 +85,23 @@ export default function QuizBox({ reactionStats, setReactionStats, quiz }: QuizB setReactionStats(data); }, []); + const handleParticipantStatistics = (response: StatisticsData) => { + setParticipantStatistics(response); + }; + useEffect(() => { socket.on('emoji', handleReactionUpdate); + socket.on('participant statistics', handleParticipantStatistics); - socket.on('timer tick', (response) => { - setTick(response); - }); - - socket.on('participant statistics', (response) => { - console.log('participant statistics', response); - }); - - socket.on('time end', (response) => { - console.log('time end', response); - }); return () => { socket.off('emoji', handleReactionUpdate); + socket.off('participant statistics', handleParticipantStatistics); }; }, []); return ( <> +
@@ -154,6 +170,8 @@ export default function QuizBox({ reactionStats, setReactionStats, quiz }: QuizB
+ + {} ); } diff --git a/packages/client/src/pages/quiz-session/ui/QuizHeader.tsx b/packages/client/src/pages/quiz-session/ui/QuizHeader.tsx index 83849401..d90efa56 100644 --- a/packages/client/src/pages/quiz-session/ui/QuizHeader.tsx +++ b/packages/client/src/pages/quiz-session/ui/QuizHeader.tsx @@ -2,7 +2,11 @@ import { useEffect, useState } from 'react'; import { getQuizSocket } from '@/shared/utils/socket'; -export default function QuizHeader() { +interface QuizHeaderProps { + tick: { currentTime: number; elapsedTime: number; remainingTime: number }; +} + +export default function QuizHeader({ tick }: QuizHeaderProps) { const socket = getQuizSocket(); const [submitStatus, setSubmitStatus] = useState<{ count: number; total: number }>({ count: 0, @@ -27,7 +31,7 @@ export default function QuizHeader() {
{submitStatus.count} / {submitStatus.total}명 제출
-
남은 시간
+
{tick.remainingTime}초 남음
); diff --git a/packages/client/src/pages/quiz-session/ui/QuizLoading.tsx b/packages/client/src/pages/quiz-session/ui/QuizLoading.tsx index d2c7cca6..c5240776 100644 --- a/packages/client/src/pages/quiz-session/ui/QuizLoading.tsx +++ b/packages/client/src/pages/quiz-session/ui/QuizLoading.tsx @@ -1,6 +1,6 @@ const QuizLoading = () => { return ( -
+
diff --git a/packages/client/tailwind.config.js b/packages/client/tailwind.config.js index 6b51cf6c..061e00e8 100644 --- a/packages/client/tailwind.config.js +++ b/packages/client/tailwind.config.js @@ -80,6 +80,21 @@ export default { from: { transform: 'rotate(0deg)' }, to: { transform: 'rotate(360deg)' }, }, + floatDown: { + '0%': { + transform: 'translateY(-100px)', + opacity: 0, + }, + '100%': { + transform: 'translateY(0)', + opacity: 1, + }, + }, + swing: { + '0%': { transform: 'rotate(0deg) translateY(0)' }, + '50%': { transform: 'rotate(30deg) translateY(-20px)' }, + '100%': { transform: 'rotate(0deg) translateY(0)' }, + }, }, }, },