|
1 |
| -import React, { useState, useContext } from 'react'; |
| 1 | +import React, { useState, useContext, useEffect } from "react"; |
2 | 2 | import { UserContext } from "../UserContextProvider";
|
3 |
| -import QuestionTable from '../components/questiontable'; |
4 |
| -import FilterCategories from '../components/filtercategory'; |
5 |
| -import FilterComplexity from '../components/filtercomplexity'; |
6 |
| -import SearchBar from '../components/searchbar'; |
7 |
| -import UploadFile from '../components/uploadquestion'; |
8 |
| -import { Question } from '../components/questiontable'; |
| 3 | +import axios from "axios"; |
| 4 | +import QuestionTable from "../components/questiontable"; |
| 5 | +import FilterCategories from "../components/filtercategory"; |
| 6 | +import FilterComplexity from "../components/filtercomplexity"; |
| 7 | +import SearchBar from "../components/searchbar"; |
| 8 | +import UploadFile from "../components/uploadquestion"; |
| 9 | +import { Question } from "../components/questiontable"; |
9 | 10 |
|
10 | 11 | const QuestionServicePage: React.FC = () => {
|
11 |
| - const [searchTerm, setSearchTerm] = useState(''); |
12 |
| - const [categoryFilter, setCategoryFilter] = useState(''); |
13 |
| - const [complexityFilter, setComplexityFilter] = useState(''); |
| 12 | + const [searchTerm, setSearchTerm] = useState(""); |
| 13 | + const [categoryFilter, setCategoryFilter] = useState(""); |
| 14 | + const [complexityFilter, setComplexityFilter] = useState(""); |
14 | 15 | const [questions, setQuestions] = useState<Question[]>([]);
|
15 |
| - const context = useContext(UserContext); |
16 |
| - const { ready } = context!; |
| 16 | + const context = useContext(UserContext); |
| 17 | + const { ready } = context!; |
17 | 18 |
|
| 19 | + const fetchQuestions = async () => { |
| 20 | + try { |
| 21 | + const response = await axios.get(`http://localhost:3002/questions/`); |
| 22 | + console.log("response is ", response); |
| 23 | + setQuestions(response.data); |
| 24 | + } catch (error) { |
| 25 | + alert("Error fetching questions: " + error); |
| 26 | + } |
| 27 | + }; |
| 28 | + |
| 29 | + useEffect(() => { |
| 30 | + fetchQuestions(); |
| 31 | + }, [questions]); |
18 | 32 |
|
19 | 33 | while (!ready) {
|
20 |
| - return ( |
21 |
| - <h1>Loading</h1> |
22 |
| - ) |
23 |
| - } |
| 34 | + return <h1>Loading</h1>; |
| 35 | + } |
24 | 36 |
|
25 | 37 | return (
|
26 | 38 | <div className="p-4 text-white">
|
27 | 39 | <h1 className="text-2xl font-bold text-left mb-6">Peer Prep</h1>
|
28 | 40 | <div className="flex justify-start items-center space-x-2 mb-4 text-sm">
|
29 | 41 | <SearchBar searchTerm={searchTerm} setSearchTerm={setSearchTerm} />
|
30 |
| - <FilterCategories category={categoryFilter} setCategory={setCategoryFilter} questions={questions} /> |
31 |
| - <FilterComplexity complexity={complexityFilter} setComplexity={setComplexityFilter} questions={questions} /> |
| 42 | + <FilterCategories |
| 43 | + category={categoryFilter} |
| 44 | + setCategory={setCategoryFilter} |
| 45 | + questions={questions} |
| 46 | + /> |
| 47 | + <FilterComplexity |
| 48 | + complexity={complexityFilter} |
| 49 | + setComplexity={setComplexityFilter} |
| 50 | + questions={questions} |
| 51 | + /> |
32 | 52 | <UploadFile setQuestions={setQuestions} />
|
33 | 53 | </div>
|
34 | 54 | <QuestionTable
|
|
0 commit comments