-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#46] 퀴즈 페이지 api 및 무한 퀴즈 챌린지 UI 변경
- Loading branch information
Showing
8 changed files
with
559 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useState } from "react"; | ||
import { fetchAnswer } from "../api/quiz.api"; | ||
|
||
export const useAnswer= () => { | ||
const [loading, setLoading] = useState<boolean>(false); | ||
const [error, setError] = useState<string | null>(null); | ||
const [isCorrectAnswer, setIsCorrect] = useState<boolean | null>(null); // 정답 여부 저장 | ||
const [correctAnswer, setCorrectAnswer] = useState<string | null>(null); // 올바른 답 저장 | ||
|
||
// 퀴즈 답안을 제출하는 함수 | ||
const submitAnswer = async (quizId: number, answer: string) => { | ||
setLoading(true); | ||
setError(null); | ||
try { | ||
const response = await fetchAnswer(quizId, answer); | ||
|
||
// 서버로부터 받은 응답에서 isCorrectAnswer와 correctAnswer를 저장 | ||
setIsCorrect(response.isCorrectAnswer); | ||
setCorrectAnswer(response.correctAnswer); | ||
|
||
return response; | ||
} catch (err) { | ||
setError('답안 제출에 실패했습니다.'); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return { loading, error, isCorrectAnswer, correctAnswer, submitAnswer }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
export interface QuizItem{ | ||
quizId: number; | ||
word: string; | ||
definition: string; | ||
initialConstant: string; | ||
wordLength: number; | ||
quizAnswerStats : IquizAnswerStats; | ||
} | ||
|
||
export interface IquizAnswerStats{ | ||
correctAnswersCount : number; | ||
totalAttemptsUntilFirstCorrectAnswer: number; | ||
|
||
} | ||
|
||
export interface quizAnswer{ | ||
isCorrectAnswer : boolean; | ||
correctAnswer : string; | ||
} | ||
|
||
export interface QuizResult { | ||
totalQuizCount: number; | ||
solvedQuizCount: number; | ||
totalQuizScore: number; | ||
quizId: number, | ||
} | ||
|
Oops, something went wrong.