From c72b49a92b31ce6ef063bc6d40b9a7f12f5da625 Mon Sep 17 00:00:00 2001 From: Jagraj Aulakh Date: Thu, 6 Apr 2023 22:04:44 -0400 Subject: [PATCH] #32 Fetch enrolled course data from backend and store the data --- frontend/src/components/CoursesWidget.jsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frontend/src/components/CoursesWidget.jsx b/frontend/src/components/CoursesWidget.jsx index 84b0f3e..f1501da 100644 --- a/frontend/src/components/CoursesWidget.jsx +++ b/frontend/src/components/CoursesWidget.jsx @@ -1,7 +1,11 @@ +import { useContext, useEffect, useState } from "react"; import { Card, Container } from "react-bootstrap"; import { Link } from "wouter"; +import UserContext from "../contexts/UserContext"; const CoursesWidget = ({ className = "" }) => { + const [courseData, setCourseData] = useState({}); + const { currentUser } = useContext(UserContext); const dummyData = [ { course_id: 1, @@ -34,6 +38,14 @@ const CoursesWidget = ({ className = "" }) => { instructor: "Arunita Jaekel", }, ]; + + useEffect(() => { + fetch(`http://localhost:5000/user/${currentUser.id}/courses`) + .then((resp) => resp.json()) + .then((data) => { + setCourseData(data.courses); + }); + }, []); return (