diff --git a/frontend/src/App.js b/frontend/src/App.js index f2771cb..8417925 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -4,6 +4,7 @@ import HomePage from "./pages/HomePage"; import LoginPage from "./pages/LoginPage"; import LogoutPage from "./pages/LogoutPage"; import RegisterPage from "./pages/RegisterPage"; +import CoursePage from "./pages/CoursePage"; import AuthenticatedRoute from "./components/AuthenticatedRoute"; function App() { @@ -20,15 +21,25 @@ function App() { - + - + + + + {(params) => { + return ( + + + + ); + }} + ); } diff --git a/frontend/src/components/AuthenticatedRoute.jsx b/frontend/src/components/AuthenticatedRoute.jsx index 5626f9a..37b417a 100644 --- a/frontend/src/components/AuthenticatedRoute.jsx +++ b/frontend/src/components/AuthenticatedRoute.jsx @@ -2,7 +2,7 @@ import { useContext, useEffect } from "react"; import { useLocation } from "wouter"; import UserContext from "../contexts/UserContext"; -const AuthenticatedRoute = ({ children, isAuthenticated }) => { +const AuthenticatedRoute = ({ children, isAuthenticated=true }) => { const { currentUser } = useContext(UserContext); const [location, setLocation] = useLocation(); diff --git a/frontend/src/components/CoursesWidget.jsx b/frontend/src/components/CoursesWidget.jsx index 1cda99d..a09ed99 100644 --- a/frontend/src/components/CoursesWidget.jsx +++ b/frontend/src/components/CoursesWidget.jsx @@ -9,6 +9,9 @@ const CoursesWidget = ({ className = "" }) => { const { currentUser } = useContext(UserContext); useEffect(() => { + if (!currentUser.id) { + return; + } makeRequest({ url: `http://localhost:5000/user/${currentUser.id}/courses` }) .then((resp) => resp.json()) .then((data) => { @@ -28,7 +31,9 @@ const CoursesWidget = ({ className = "" }) => { className="col col-lg-2" > -

{course.course_code}

+

+ {course.course_code} +

{course.name} {course.instructor} diff --git a/frontend/src/pages/CoursePage.jsx b/frontend/src/pages/CoursePage.jsx new file mode 100644 index 0000000..ac62920 --- /dev/null +++ b/frontend/src/pages/CoursePage.jsx @@ -0,0 +1,30 @@ +import { useEffect, useState } from "react"; +import { Container } from "react-bootstrap"; +import MyNavbar from "../components/MyNavbar"; +import { makeRequest } from "../utils.ts"; + +const CoursePage = ({ id }) => { + const [courseData, setCourseData] = useState({}); + + useEffect(() => { + makeRequest({ url: `http://localhost:5000/course/${id}` }) + .then((resp) => resp.json()) + .then((data) => { + setCourseData(data); + }); + }, []); + + return ( +
+ + +

{courseData.name}

+

{courseData.instructor}

+
+

Assignments

+
+
+ ); +}; + +export default CoursePage;