Skip to content

Commit

Permalink
refactor: modify code for api call for problem statements
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeMaster17 committed Sep 4, 2024
1 parent 895592f commit aa959c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 13 additions & 0 deletions frontend/src/api/problemApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PROBLEM_ROUTE } from "@/constants";

export const getAllProblems = async () => {
const response = await fetch(`${PROBLEM_ROUTE}/all`);

if (!response.ok) {
throw new Error("Failed to fetch problems");
}

const data = await response.json();
console.log(typeof data);
return data;
};
8 changes: 2 additions & 6 deletions frontend/src/pages/ProblemSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import {

import { Input } from "@/components/ui/input";
import Navbar from "@/components/Navbar/Navbar";
import { PROBLEM_ROUTE } from "@/constants";
import { useNavigate } from "react-router-dom";
import { IProblem, ITag } from "@/types/types";
import { getCurrentProblems, getProblemsBySearchQuery, getTotalPages } from "@/lib/utils";
import { EASY_DIFFICULTY, MEDIUM_DIFFICULTY } from "@/constants/problemConstants";
import { getAllProblems } from "@/api/problemApi";



Expand All @@ -46,11 +46,7 @@ const ProblemSet = () => {
useEffect(() => {
const fetchProblems = async () => {
try {
const response = await fetch(`${PROBLEM_ROUTE}/all`);
if (!response.ok) {
throw new Error("Failed to fetch problems");
}
const data = await response.json();
const data: IProblem[] = await getAllProblems();
setProblems(data);
setTotalProblems(data.length);
setLoading(false);
Expand Down

0 comments on commit aa959c2

Please sign in to comment.