From eba147b988d01c8a17ce19a409ff27ed7ffe0b2a Mon Sep 17 00:00:00 2001 From: Harshitha Shetty <141444342+HarshithaShetty27@users.noreply.github.com> Date: Sat, 8 Mar 2025 05:21:26 +0530 Subject: [PATCH] Fixed navbar issue, added panel Consolidated page --- client/src/App.js | 2 + client/src/Pages/Accounts.jsx | 3 +- client/src/Pages/PanelConsolidated.jsx | 115 +++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 client/src/Pages/PanelConsolidated.jsx diff --git a/client/src/App.js b/client/src/App.js index 6c8362d..d4058f6 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -15,6 +15,7 @@ import CourseConsolidated from "./Pages/courseConsolidated"; import PrivateRoute from "./components/PrivateRoute"; import TokenRefresher from "./components/TokenRefresher"; import DepartmentConsolidated from "./Pages/DepartmentConsolidated"; +import PanelConsolidated from "./Pages/PanelConsolidated"; function App() { return ( @@ -32,6 +33,7 @@ function App() { } />} /> } />} /> } />} /> + } />} /> ); diff --git a/client/src/Pages/Accounts.jsx b/client/src/Pages/Accounts.jsx index b5e4ae3..eb45b33 100644 --- a/client/src/Pages/Accounts.jsx +++ b/client/src/Pages/Accounts.jsx @@ -1,8 +1,9 @@ import React, { useState, useEffect } from "react"; -import { Container, Col, Row, Button, Spinner, Navbar } from "react-bootstrap"; +import { Container, Col, Row, Button, Spinner } from "react-bootstrap"; import axios from "axios"; import { ToastContainer, toast } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; +import Navbar from "./Navbar"; function HomePage(props) { diff --git a/client/src/Pages/PanelConsolidated.jsx b/client/src/Pages/PanelConsolidated.jsx new file mode 100644 index 0000000..a636975 --- /dev/null +++ b/client/src/Pages/PanelConsolidated.jsx @@ -0,0 +1,115 @@ +import React, { useState, useEffect } from "react"; +import axios from "axios"; +import Navbar from "./Navbar"; + +const PanelConsolidated = () => { + const [faculty, setFaculty] = useState([]); + const [courses, setCourses] = useState([]); + const [search, setSearch] = useState(""); + const [expandedCourse, setExpandedCourse] = useState(null); + + useEffect(() => { + axios.get("http://localhost:8080/api/faculty") + .then((response) => { + setFaculty(response.data); + }) + .catch((error) => { + console.error("Error fetching faculty data:", error); + }); + + axios.get("http://localhost:8080/api/courses") + .then((response) => { + setCourses(response.data); + }) + .catch((error) => { + console.error("Error fetching course data:", error); + }); + }, []); + + const filteredCourses = courses.filter((course) => + course.name.toLowerCase().includes(search.toLowerCase()) + ); + + const courseFacultyMap = {}; + faculty.forEach((fac) => { + fac.courses.forEach((courseId) => { + if (!courseFacultyMap[courseId]) { + courseFacultyMap[courseId] = []; + } + courseFacultyMap[courseId].push({ + facultyId: fac.facultyId, + name: fac.name, + department: fac.department, + email: fac.email, + }); + }); + }); + + const toggleCourse = (courseId) => { + setExpandedCourse(expandedCourse === courseId ? null : courseId); + }; + + return ( + <> + +
+

Faculty Expertise

+ + setSearch(e.target.value)} + /> + +
+ {filteredCourses.map((course) => ( +
+
toggleCourse(course.courseId)} + style={{ + cursor: "pointer", + padding: "12px", + backgroundColor: "#fff", + marginBottom: "8px", + border: "1px solid #ccc", + borderRadius: "4px", + fontWeight: "bold" + }} + > + {course.name} +
+ {expandedCourse === course.courseId && ( + + + + + + + + + + + {courseFacultyMap[course.courseId]?.map((faculty, index) => ( + + + + + + + ))} + +
Faculty IDNameEmailDepartment
{faculty.facultyId}{faculty.name}{faculty.email}{faculty.department}
+ )} +
+ + ))} +
+
+ + ); +}; + + +export default PanelConsolidated;