Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
huangrandy committed Jan 14, 2024
2 parents b414841 + 2934a6a commit a62a32e
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/components/Dashboard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ function Dashboard() {

)}
</Content>
<RequirementsSidebar changeDepartment={setDepartment} changeColorSchema={setColorSchema} />
<RequirementsSidebar changeDepartment={setDepartment} changeColorSchema={setColorSchema} userCourses={coursesTaken}/>
</Layout>
</Layout>
<Modal title="Get Started!" open={signup} onCancel={handleClose} footer={[]}>
Expand Down
209 changes: 159 additions & 50 deletions src/components/Dashboard/Requirements/Requirements.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useEffect, useState } from "react";
import "./Requirements.css"
import {
Dropdown,
Expand All @@ -7,6 +7,9 @@ import {
Progress,
}
from 'antd';
import RequestUtils from "../../../Utils/RequestUtils";
import { useAuthState } from "react-firebase-hooks/auth";
import { auth } from "../../../Firebase";
const { Header, Content, Footer, Sider } = Layout;

const courses = [
Expand Down Expand Up @@ -44,32 +47,153 @@ const courses = [
},
];

const allRequirements = {
const CSRequirements = {
"systems": [
"CS 3013",
"CS 4516",
"CS 4513",
"CS 4515"
],
"design": [
"CS 3733",
"CS 3431",
"CS 3041",
"CS 4233"
],
"theory": [
"CS 3133",
"CS 4123",
"CS 4533",
"CS 4120",
"CS 4536"
],
"socImps" : [
"CS 3043",
"GOV 2314",
"GOV 2315",
"IMGD 2000",
"IMGD 2001",
"RBE 3100"
]
};


const colors = [
{
value: "plain",
label: "Plain"
},
{
value: "tot",
label: "Total Rating"
},
{
value: "level",
label: "Level"
},
{
value: "area",
label: "Area"
},
{
value: "diff",
label: "Difficulty"
},
{
value: "prof",
label: "Professor Rating"
},
{
value: "course",
label: "Course Rating"
},
]

const depNames = {
"cs": "Computer Science Department",
"hua": "Humanities and Arts Department",
"wpe": "Physical Education and Athletics Department",
"ss": "Social Science and Policy Studies Department",
"math": "Mathematical Sciences Department",
// need iqp, mqp, fe, sci
}


function RequirementsSidebar({changeDepartment, changeColorSchema, className="", userCourses}) {

let [user, loading] = useAuthState(auth);

// CS Req array
let [csReqs, setCSReqs] = useState([0,0,0,0,0]);
let [huaReqs, setHUAReqs] = useState([0,0,0,0]);
let [wpeReqs, setWPEReqs] = useState([0]);
let [ssReqs, setSSReqs] = useState([0]);
let [iqpReqs, setIQPReqs] = useState([0]);
let [mqpReqs, setMQPReqs] = useState([0]);
let [mathReqs, setMathReqs] = useState([0,0,0]);
let [feReqs, setFEReqs] = useState([0]);
let [sciReqs, setSciReqs] = useState([0,0]);

function addReq() {
for(let i = 0; i < userCourses.length; i++) {
if(userCourses[i].courseCode.substring(4,5) == "4") {
let temp = csReqs;
temp[0] += 1;
setCSReqs(temp);
}
else if(CSRequirements["systems"].includes(userCourses[i].courseCode)) {
let temp = csReqs;
temp[1] += 1;
setCSReqs(temp);
} else if(CSRequirements["design"].includes(userCourses[i].courseCode)) {
let temp = csReqs;
temp[2] += 1;
setCSReqs(temp);
} else if(CSRequirements["theory"].includes(userCourses[i].courseCode)) {
let temp = csReqs;
temp[3] += 1;
setCSReqs(temp);
} else if(CSRequirements["socImps"].includes(userCourses[i].courseCode)) {
let temp = csReqs;
temp[4] += 1;
setCSReqs(temp);
}


}
}
useEffect(() => {
if(user) {
addReq();
}
}, [userCourses]);

const allRequirements = {
'cs': [
{
label: "4000-Level Courses",
needed: 5,
filled: 3,
filled: csReqs[0],
},
{
label: "Systems",
needed: 1,
filled: 0,
filled: csReqs[1],
},
{
label: "Design",
needed: 1,
filled: 1,
filled: csReqs[2],
},
{
label: "Theory",
needed: 5,
filled: 2,
filled: csReqs[3],
},
{
label: "Social",
needed: 1,
filled: 0,
filled: csReqs[4],
}
],
'hua': [
Expand Down Expand Up @@ -160,55 +284,40 @@ const allRequirements = {
]
};

const colors = [
{
value: "plain",
label: "Plain"
},
{
value: "tot",
label: "Total Rating"
},
{
value: "level",
label: "Level"
},
{
value: "area",
label: "Area"
},
{
value: "diff",
label: "Difficulty"
},
{
value: "prof",
label: "Professor Rating"
},
{
value: "course",
label: "Course Rating"
},

]

const depNames = {
"cs": "Computer Science Department",
"hua": "Humanities and Arts Department",
"wpe": "Physical Education and Athletics Department",
"ss": "Social Science and Policy Studies Department",
"math": "Mathematical Sciences Department",
// need iqp, mqp, fe, sci
}


function RequirementsSidebar({ changeDepartment, changeColorSchema, className = "" }) {

const [requirements, setRequirements] = useState(allRequirements['cs'])

const setReqCategory = (category) => {
setRequirements(allRequirements[category])
}


function getAllCourses() {
// RequestUtils.get("/retrieve?id=" + user.uid).then((response) => response.json())
// .then((data) => {
// console.log("Test")
// let courses = data.data.courses;
// if(courses == undefined) {
// courses = [];
// }
// let temp = [];
// for(let i = 0; i < courses.length; i++) {
// console.log(courses[i]);
// temp.push(courses[i].courseCode);
// }
// console.log(temp);
// });
}

useEffect(() => {
if(user) {
getAllCourses();
}

}, []);



return (
<Sider className={className} style={{ paddingTop: '0.5rem', paddingLeft: '1.8rem', paddingRight: '1.8rem', color: "white", }}
width="auto">
Expand Down
38 changes: 35 additions & 3 deletions src/components/DataParse/ClassCard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useEffect } from "react";
import { useNavigate } from "react-router";
import { Card, Progress } from 'antd';
import { CodeOutlined, PlusSquareOutlined, InfoCircleOutlined } from '@ant-design/icons';
import { CodeOutlined, PlusSquareOutlined, InfoCircleOutlined, MinusCircleOutlined, MinusSquareOutlined } from '@ant-design/icons';
import profRatings from './ProfessorRating.json';
import classRatings from './CourseRatings.json';
import { useAuthState } from "react-firebase-hooks/auth";
Expand All @@ -19,6 +19,8 @@ const ClassCard = ({ index }) => {
const [OSCARatings, setOscarRatings] = useState([0, 0, 0]);
//console.log(data["Report_Entry"][index]);

let [code, setCode] = useState(0);

const getCourseDescription = (inputString) => {
const endIndex = inputString.toLowerCase().indexOf("recommended background");
const firstString = inputString.slice(0, endIndex);
Expand All @@ -34,6 +36,25 @@ const ClassCard = ({ index }) => {
return [profRating, courseRating, projRating]
}

function getCurrentCourses() {

RequestUtils.get("/retrieve?id=" + user.uid).then((response) => response.json())
.then((data) => {

let courses = data.data.courses;

if(courses == undefined) {
courses = [];
}
for(let i = 0; i < courses.length; i++) {
if(courses[i].courseCode == courseCode) {
setCode(1);
}
}
});

}

function addCourse() {

RequestUtils.get("/retrieve?id=" + user.uid).then((response) => response.json())
Expand Down Expand Up @@ -66,12 +87,22 @@ const ClassCard = ({ index }) => {
// });
// }
});

}

function removeCourse() {
let reqobj = {
course : courseCode
}
RequestUtils.post("/delete?id=" + user.uid, reqobj).then((response) => {
alert("Course removed!");
window.location.reload();
});
}

useEffect(() => {
// Call the function once on component mount
setOscarRatings(getOSCARRatings());
getCurrentCourses();
}, []);


Expand All @@ -83,7 +114,8 @@ const ClassCard = ({ index }) => {
title={data["Report_Entry"][index]["Course_Title"].slice(10,).trim()}
// + " (" + data["Report_Entry"][index]["Course_Title"].slice(0, 8).trim() + ")"
extra={<CodeOutlined style={{ color: "white" }} />}
actions={[<a onClick={() => addCourse(courseCode)}>{<PlusSquareOutlined />}</a>, <a href="https://courselistings.wpi.edu" target="_blank">{<InfoCircleOutlined />}</a>]}
actions={[<a onClick={() =>
code == 0 ? addCourse() : removeCourse()}>{code == 0 ? <PlusSquareOutlined /> : <MinusSquareOutlined></MinusSquareOutlined>}</a>, <a href="https://courselistings.wpi.edu" target="_blank">{<InfoCircleOutlined />}</a>]}
bodyStyle={{
padding: 5,
lineHeight: 1,
Expand Down
15 changes: 9 additions & 6 deletions src/components/Table/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ const EditableCell = ({

RequestUtils.post("/update", fullObj).then((response) => response.json())
.then((data) => {
console.log(data);

});

console.log({...record, ...values})

} catch (errInfo) {
console.log('Save failed:', errInfo);
}
Expand Down Expand Up @@ -123,8 +120,6 @@ const App = () => {
} catch (err){
console.log(err);
}
console.log(data.data.courses);
console.log(temp)
setDataSource(temp);
});
}
Expand All @@ -135,6 +130,14 @@ const App = () => {
const handleDelete = (key) => {
const newData = dataSource.filter((item) => item.key !== key);
setDataSource(newData);

let reqObj = {
course: dataSource[key].course,
}

RequestUtils.post("/delete?id=" + user.uid, reqObj).then((response) => response.json()).then((data) => {
alert("Course Deleted!")
});
};

const defaultColumns = [
Expand Down

0 comments on commit a62a32e

Please sign in to comment.