Merge branch 'fe/fixQuizAPI' into 'frontend'
[Front-End] fix: 퀴즈 가져오는 API 수정 See merge request s11-webmobile1-sub2/S11P12A701!74
This commit is contained in:
commit
4637b4911b
@ -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;
|
||||
}
|
||||
|
||||
|
10
frontend/src/hooks/api/useStudentQuizsetDetail.js
Normal file
10
frontend/src/hooks/api/useStudentQuizsetDetail.js
Normal 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}`),
|
||||
});
|
||||
}
|
@ -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}`),
|
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user