From dccc1949e01fcb5f3b8ef898a9309e105feb79cb Mon Sep 17 00:00:00 2001 From: Jagraj Aulakh Date: Fri, 14 Apr 2023 17:06:25 -0400 Subject: [PATCH] #47 Made manage content page --- frontend/src/App.js | 11 ++ frontend/src/pages/ManageContentPage.jsx | 149 +++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 frontend/src/pages/ManageContentPage.jsx diff --git a/frontend/src/App.js b/frontend/src/App.js index 88dffa6..e196e52 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -10,6 +10,7 @@ import ManagePage from "./pages/ManagePage"; import ManageStudentsPage from "./pages/ManageStudentsPage"; import AuthenticatedRoute from "./components/AuthenticatedRoute"; import ManageAssignmentsPage from "./pages/ManageAssignmentsPage"; +import ManageContentPage from "./pages/ManageContentPage"; const AuthRoute = ({ isAuthenticated = true, path, children }) => { return ( @@ -72,6 +73,16 @@ function App() { }} + + {(params) => { + return ( + + + + ); + }} + + {(params) => { return ( diff --git a/frontend/src/pages/ManageContentPage.jsx b/frontend/src/pages/ManageContentPage.jsx new file mode 100644 index 0000000..f1be1ea --- /dev/null +++ b/frontend/src/pages/ManageContentPage.jsx @@ -0,0 +1,149 @@ +import { useEffect, useState } from "react"; +import { Container, Table, Button, Form } from "react-bootstrap"; +import MyNavbar from "../components/MyNavbar"; +import { makeRequest } from "../utils.ts"; + +const ManageContentPage = ({ cid }) => { + const [courseData, setCourseData] = useState({}); + const [contentData, setContentData] = useState([]); + const [showAddContentForm, setShowAddContentForm] = useState(false); + + const AddContentForm = () => { + const [name, setName] = useState(""); + const [body, setBody] = useState(""); + + return ( +
+
{ + submitContentForm(name, body); + }} + > + + Name + setName(e.target.value)} + /> + + + Body + setBody(e.target.value)} + /> + + +
+
+ ); + }; + + const submitContentForm = (name, body) => { + makeRequest({ + endpoint: "content", + method: "POST", + body: { + name, + body, + course_id: cid, + }, + }); + }; + + const sendDeleteContentRequest = (id) => { + makeRequest({ + endpoint: `content/${id}`, + method: "DELETE", + }).then((resp) => { + window.location.reload(); + }); + }; + + useEffect(() => { + makeRequest({ + endpoint: `course/${cid}/content`, + method: "GET", + }) + .then((req) => req.json()) + .then(async (data) => { + setContentData(data.content); + }) + .catch((err) => { + console.error(err); + }); + + makeRequest({ + endpoint: `course/${cid}`, + method: "GET", + }) + .then((req) => req.json()) + .then(async (data) => { + setCourseData(data); + }) + .catch((err) => { + console.error(err); + }); + }, []); + + return ( +
+ + +

{courseData.name}

+

Manage Course Content

+ + {showAddContentForm && } + + + + + + + + + + + {contentData.map((content, k) => { + return ( + + + + + + + ); + })} + +
#NameCreatedManage
{content.id}{content.name}{content.created_at} +
+ +
+
+
+
+ ); +}; + +export default ManageContentPage;