fix: 퀴즈 가져오는 API 수정

This commit is contained in:
jhynsoo 2024-08-06 17:52:36 +09:00
parent afd7b10869
commit 22ea1581f1
4 changed files with 16 additions and 5 deletions

View File

@ -1,16 +1,16 @@
import styles from './QuizSet.module.css';
import { useCallback, useEffect, useRef, useState } from 'react';
import { useQuizsetDetail } from '../../hooks/api/useQuizsetDetail';
import Quiz from '../Quiz/Quiz';
import { useParams } from 'react-router-dom';
import LoadingIndicator from '../LoadingIndicator.jsx/LoadingIndicator';
import instance from '../../utils/axios/instance';
import { API_URL } from '../../constants';
import { useStudentQuizsetDetail } from '../../hooks/api/useStudentQuizsetDetail';
export default function QuizSet({ quizSetId, finish }) {
const { roomId } = useParams();
const [step, setStep] = useState(null);
const { data } = useQuizsetDetail(quizSetId);
const { data } = useStudentQuizsetDetail(quizSetId);
const quizSetData = data?.data;
const quizList = quizSetData.quizzes;
const answers = useRef(Array(quizList.length).fill(null));
@ -52,8 +52,9 @@ export default function QuizSet({ quizSetId, finish }) {
return 0;
}
if (prev === quizList.length) {
if (prev + 1 === quizList.length) {
submit(answers.current);
} else if (prev === quizList.length) {
return Infinity;
}

View File

@ -0,0 +1,10 @@
import { useSuspenseQuery } from '@tanstack/react-query';
import instance from '../../utils/axios/instance';
import { API_URL } from '../../constants';
export function useStudentQuizsetDetail(id) {
return useSuspenseQuery({
queryKey: ['quizset', id],
queryFn: () => instance.get(`${API_URL}/quiz/student/${id}`),
});
}

View File

@ -2,7 +2,7 @@ import { useSuspenseQuery } from '@tanstack/react-query';
import instance from '../../utils/axios/instance';
import { API_URL } from '../../constants';
export function useQuizsetDetail(id) {
export function useTeacherQuizsetDetail(id) {
return useSuspenseQuery({
queryKey: ['quizset', id],
queryFn: () => instance.get(`${API_URL}/quiz/teacher/${id}`),

View File

@ -1,4 +1,4 @@
import { useQuizsetDetail } from '../../hooks/api/useQuizsetDetail';
import { useQuizsetDetail } from '../../hooks/api/useTeacherQuizsetDetail';
import { useParams, useNavigate } from 'react-router-dom';
import { QuizsetDetail } from '../../components/QuizsetDetail';
import { useQuizsetDelete } from '../../hooks/api/useQuizsetDelete';