Skip to content

Commit

Permalink
Add call to useMatchmaking
Browse files Browse the repository at this point in the history
  • Loading branch information
gycgabriel committed Oct 31, 2023
1 parent eb5b23d commit facf301
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
6 changes: 6 additions & 0 deletions frontend/src/hooks/useMatchmaking.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useContext } from "react";
import { MatchmakingContext } from "../providers/MatchmakingProvider";
import { getMatchByRoomid } from "@/pages/api/matchHandler";

export function useMatchmaking() {
const context = useContext(MatchmakingContext);
Expand All @@ -8,3 +9,8 @@ export function useMatchmaking() {
}
return context;
}

export const getQuestionIdFromMatch = async (roomId: string) => {
const match = await getMatchByRoomid(roomId);
return match?.questionId;
};
21 changes: 12 additions & 9 deletions frontend/src/pages/room/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useRouter } from "next/router";
import VideoRoom from "../../components/room/video-room";
import { Question } from "../../types/QuestionTypes";
import { useQuestions } from "@/hooks/useQuestions";
import { getQuestionIdFromMatch } from "@/hooks/useMatchmaking";

export default function Room() {
const router = useRouter();
Expand Down Expand Up @@ -38,17 +39,19 @@ export default function Room() {
const { fetchQuestion } = useQuestions();

async function getQuestionId() {
return "1"; // todo
return getQuestionIdFromMatch(roomId); // todo
}

getQuestionId().then((questionId) =>
fetchQuestion(questionId).then((fetchQuestion) => {
if (fetchQuestion != null) {
question = fetchQuestion;
setQuestionId(question.id);
}
})
);
getQuestionId().then((questionId) => {
if (questionId != null) {
fetchQuestion(questionId).then((fetchQuestion) => {
if (fetchQuestion != null) {
question = fetchQuestion;
setQuestionId(question.id);
}
});
}
});

if (!router.isReady) return null;

Expand Down

0 comments on commit facf301

Please sign in to comment.