From ff2361094326662b57cc0d948eaf441eb043d650 Mon Sep 17 00:00:00 2001 From: GuDoYoon Date: Wed, 30 Oct 2024 12:00:11 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Feature(#46):=20Quiz=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/{quiz.ts => quizzes.ts} | 6 +++--- src/features/Quiz/ui/TotalResult.tsx | 0 src/hooks/useQueryParams.ts | 1 - src/pages/Quiz/Quiz.tsx | 9 ++++++--- src/route/Router.tsx | 2 +- src/types/Quiz.ts | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) rename src/apis/{quiz.ts => quizzes.ts} (82%) delete mode 100644 src/features/Quiz/ui/TotalResult.tsx diff --git a/src/apis/quiz.ts b/src/apis/quizzes.ts similarity index 82% rename from src/apis/quiz.ts rename to src/apis/quizzes.ts index 54e0a24..5b694e7 100644 --- a/src/apis/quiz.ts +++ b/src/apis/quizzes.ts @@ -2,8 +2,8 @@ import { useQuery } from '@tanstack/react-query'; import Quiz from '../types/Quiz'; import api from './axios/instance'; -const QUIZ = { - getQuizzes: (sectionId: string | null, part: string | null) => { +const QuizzesApi = { + get: (sectionId: Quiz['sectionId'], part: Quiz['part']) => { return useQuery({ queryKey: ['quizzes', { sectionId, part }], queryFn: () => @@ -17,4 +17,4 @@ const QUIZ = { }); }, }; -export default QUIZ; +export default QuizzesApi; diff --git a/src/features/Quiz/ui/TotalResult.tsx b/src/features/Quiz/ui/TotalResult.tsx deleted file mode 100644 index e69de29..0000000 diff --git a/src/hooks/useQueryParams.ts b/src/hooks/useQueryParams.ts index d07c053..230a6d4 100644 --- a/src/hooks/useQueryParams.ts +++ b/src/hooks/useQueryParams.ts @@ -12,7 +12,6 @@ function useQueryParams(params: string[]): (string | null)[] { params.forEach(param => { result.push(queryParams.get(param)); }); - return result; } diff --git a/src/pages/Quiz/Quiz.tsx b/src/pages/Quiz/Quiz.tsx index 32e1e21..327d788 100644 --- a/src/pages/Quiz/Quiz.tsx +++ b/src/pages/Quiz/Quiz.tsx @@ -5,7 +5,7 @@ import { HeaderSection, ProgressSection, TotalResultsSection, -} from './styles'; +} from '../quiz/styles'; import type Quiz from '../../types/Quiz'; import { useClientQuizStore } from '../../store/useQuizStore'; import Combination from '../../features/quiz/ui/Combination'; @@ -14,13 +14,13 @@ import OXSelector from '../../features/quiz/ui/OXSelector'; import ShortAnswer from '../../features/quiz/ui/ShortAnswer'; import componentMapping from '../../utils/componentMap'; import useRefreshWaringAlert from '../../hooks/useRefreshWaringAlert'; -import QUIZ from '../../apis/quiz'; import ResultModal from '../../features/quiz/ui/ResultModal'; import useQueryParams from '../../hooks/useQueryParams'; import TotalResults from '../../features/quiz/ui/TotalResults'; import { useState } from 'react'; import arraysEqual from '../../utils/arraysEqual'; import { ResponseButton, SubmitSection } from '../../features/quiz/styles'; +import QuizzesApi from './../../apis/quizzes'; //퀴즈페이지 export default function Quiz() { const { currentPage, totalResults, userResponseAnswer } = @@ -29,7 +29,10 @@ export default function Quiz() { const [result, setResult] = useState(false); const [isResultModal, setIsResultModal] = useState(false); useRefreshWaringAlert(); - const { data: quizzes, isLoading } = QUIZ.getQuizzes(section, part); + if (section === null || part === null) { + return
404
; + } + const { data: quizzes, isLoading } = QuizzesApi.get(Number(section), part); if (isLoading) return
Loading
; if (!quizzes) return
404
; if (quizzes.length === totalResults.length) { diff --git a/src/route/Router.tsx b/src/route/Router.tsx index c3403bc..14a2d8e 100644 --- a/src/route/Router.tsx +++ b/src/route/Router.tsx @@ -2,7 +2,7 @@ import { BrowserRouter, Route, Routes } from 'react-router-dom'; import Main from '../pages/main/Main'; import Quest from '../pages/Quest/Quest'; import Ranking from '../pages/Ranking/Ranking'; -import Quiz from '../pages/Quiz/Quiz'; +import Quiz from '../pages/quiz/Quiz'; import Admin from '../admin/Admin'; import CreateQuiz from '../admin/CreateQuiz'; import Login from '../pages/login/Login'; diff --git a/src/types/Quiz.ts b/src/types/Quiz.ts index 0077cfa..9936c82 100644 --- a/src/types/Quiz.ts +++ b/src/types/Quiz.ts @@ -1,6 +1,6 @@ export default interface Quiz { id: number; - partId: number; + part: string; sectionId: number; title: string; question: string;