From ee789bff7faaeaa41632a5af6b0c88e3aae35493 Mon Sep 17 00:00:00 2001 From: Ong Jun Xiong Date: Mon, 9 Oct 2023 01:08:44 +0800 Subject: [PATCH] fix grab questions --- frontend/src/pages/questions/index.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/frontend/src/pages/questions/index.tsx b/frontend/src/pages/questions/index.tsx index a8e977b0..c1755a4f 100644 --- a/frontend/src/pages/questions/index.tsx +++ b/frontend/src/pages/questions/index.tsx @@ -6,28 +6,28 @@ import { } from "@/components/ui/typography"; import Link from "next/link"; import { Button } from "@/components/ui/button"; -import {useContext, useEffect, useState} from "react"; +import { useContext, useEffect, useState } from "react"; import DifficultySelector from "@/components/common/difficulty-selector"; import { columns, Question } from "@/components/questions/columns"; import { DataTable } from "@/components/questions/data-table"; import { Difficulty } from "../../../types/QuestionTypes"; -import {questionApiPathAddress} from "@/firebase-client/gateway-address"; -import {AuthContext} from "@/contexts/AuthContext"; +import { questionApiPathAddress } from "@/firebase-client/gateway-address"; +import { AuthContext } from "@/contexts/AuthContext"; export default function Questions() { const [difficulty, setDifficulty] = useState("medium"); const [questions, setQuestions] = useState([]); - const { currentUser, authIsReady } = useContext(AuthContext); - + const { user: currentUser, authIsReady } = useContext(AuthContext); useEffect(() => { if (currentUser) { const url = `${questionApiPathAddress}list`; + console.log(currentUser, authIsReady); currentUser.getIdToken(true).then((idToken) => { fetch(url, { method: "GET", - mode: 'cors', + mode: "cors", headers: { "Content-Type": "application/json", "User-Id-Token": idToken, @@ -36,6 +36,7 @@ export default function Questions() { .then((response) => response.json()) .then((data) => { if (data && data.questions) { + console.log(data); setQuestions( data.questions.map((question: any) => ({ title: question.title, @@ -50,9 +51,9 @@ export default function Questions() { }); }); } else { - console.log("You are most likely not logged in") + console.log("You are most likely not logged in"); } - }, []); + }, [currentUser, authIsReady]); return (