Skip to content
Snippets Groups Projects
Commit 735e6f86 authored by GOEPP THOMAS's avatar GOEPP THOMAS
Browse files

:twisted_rightwards_arrows: merge refactor: multi sse

Merge branch 'feature/56-sse-in-game' into 'develop'
parents e7d46a12 e298b4c1
Branches
2 merge requests!76V4.1,!65refactor: multi sse
Pipeline #325808 passed with stage
in 5 seconds
......@@ -75,7 +75,7 @@ export function PlayingQuizMulti() {
) : (
<>
<QuizTopMulti quizInformations={null} actualQuestion={actualQuestion} score={score} questionCount={questionCount} setStopQuizModalIsOpen={setStopQuizModalIsOpen} />
<QuizBotMulti actualQuestion={actualQuestion} isHost={true} setPlayingQuizState={setPlayingQuizState} playingQuizState={playingQuizState} OpenModalEndQuiz={setEndQuizModalIsOpen}/>
<QuizBotMulti actualQuestion={actualQuestion} isHost={true} setPlayingQuizState={setPlayingQuizState} playingQuizState={playingQuizState} OpenModalEndQuiz={setEndQuizModalIsOpen} setScore={setScore}/>
<StopQuizModal isOpen={stopQuizModalIsOpen} onClose={() => setStopQuizModalIsOpen(false)} />
<EndQuizModalMulti
isOpen={endQuizModalIsOpen}
......
......@@ -8,6 +8,7 @@ import {Question} from "../../../../models/Question.ts";
import {AnswerSSEResponse} from "../../../../models/Response/AnswerSSEResponse.ts";
import {useEventSourceContext} from "../../../../components/EventSourceContextType.tsx";
import {PlayingQuizState} from "../../../../models/PlayingQuizState.ts";
import HttpError from "../../../../services/HttpError.ts";
interface Props {
actualQuestion: Question;
......@@ -15,6 +16,7 @@ interface Props {
setPlayingQuizState: (playingQuizState: PlayingQuizState) => void;
playingQuizState: PlayingQuizState;
OpenModalEndQuiz: (bool: boolean) => void;
setScore: (score: number) => void;
}
......@@ -38,12 +40,12 @@ const getStyleOfAnswerButton = (
}
return "answer-button";
};
export function QuizBotMulti({ actualQuestion, isHost, playingQuizState, setPlayingQuizState }: Props) {
export function QuizBotMulti({ actualQuestion, isHost, playingQuizState, setPlayingQuizState, setScore }: Props) {
const [questionIsFinished, setQuestionIsFinished] = useState(false);
const [selectedAnswerId, setSelectedAnswerId] = useState<number | null>(null);
const [validationButtonIsDisabled, setValidationButtonIsDisabled] = useState(true);
const [correctAnswerId, setCorrectAnswerId] = useState<number | null>(null);
const { nextQuestion, answerQuestion, revealAnswer } = useMultiplayerService();
const { nextQuestion, answerQuestion, revealAnswer, getScore } = useMultiplayerService();
const { eventSource } = useEventSourceContext();
const initSSE = async () => {
......@@ -75,6 +77,13 @@ export function QuizBotMulti({ actualQuestion, isHost, playingQuizState, setPlay
{
await revealAnswer();
}
const scoreFetched = await getScore();
if(HttpError.isHttpError(scoreFetched))
{
return;
}
setScore(scoreFetched);
};
const onContinue = () => {
......
......@@ -160,6 +160,25 @@ export const useMultiplayerService = () => {
}
};
const getScore = async () : Promise<number | HttpError> => {
console.log("getScore");
try {
const response = await axios.get(`${url}/party/score`, {
withCredentials: true,
});
console.log("getScore done");
return response.data.score;
} catch (error: any) {
console.log("Error while startParty:", error);
if (error.response) {
return new HttpError(error.response.status, error.response.data?.message || "HTTP error");
} else {
return new HttpError(500, "Unexpected error: " + error.message);
}
}
};
return {
createParty,
getCategories,
......@@ -176,5 +195,6 @@ export const useMultiplayerService = () => {
revealAnswer,
answerQuestion,
nextQuestion,
getScore,
};
};
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment