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)} + /> + + + Submit + + + + ); + }; + + 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 + { + setShowAddContentForm(!showAddContentForm); + }} + > + {(showAddContentForm && "-") || "+"} Add course content + + {showAddContentForm && } + + + + # + Name + Created + Manage + + + + {contentData.map((content, k) => { + return ( + + {content.id} + {content.name} + {content.created_at} + + + + sendDeleteContentRequest(content.id) + } + > + Delete + + + + + ); + })} + + + + + ); +}; + +export default ManageContentPage;