Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address remaining lint warnings #510

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 51 additions & 50 deletions site/src/component/GradeDist/GradeDist.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useState, useEffect } from 'react';
import React, { FC, useState, useEffect, useCallback } from 'react';
import { Dropdown, Grid, DropdownProps } from 'semantic-ui-react';
import Chart from './Chart';
import Pie from './Pie';
Expand All @@ -21,8 +21,9 @@ interface Entry {

type ChartTypes = 'bar' | 'pie';

const quarterOrder: QuarterName[] = ['Winter', 'Spring', 'Summer1', 'Summer10wk', 'Summer2', 'Fall'];

const GradeDist: FC<GradeDistProps> = (props) => {
const quarterOrder: QuarterName[] = ['Winter', 'Spring', 'Summer1', 'Summer10wk', 'Summer2', 'Fall'];
/*
* Initialize a GradeDist block on the webpage.
* @param props attributes received from the parent element
Expand All @@ -37,7 +38,7 @@ const GradeDist: FC<GradeDistProps> = (props) => {
const [courseEntries, setCourseEntries] = useState<Entry[]>(null!);
const [quarterEntries, setQuarterEntries] = useState<Entry[]>(null!);

const fetchGradeDistData = () => {
const fetchGradeDistData = useCallback(() => {
let requests: Promise<GradesRaw>[];
// course context
if (props.course) {
Expand All @@ -57,13 +58,49 @@ const GradeDist: FC<GradeDistProps> = (props) => {
setGradeDistData([]);
console.error(error.response);
});
};
}, [props.course, props.professor]);

// reset any data from a previous course or professor, get new data for course or professor
useEffect(() => {
setGradeDistData(null!);
fetchGradeDistData();
}, [props.course?.id, props.professor?.ucinetid]);
}, [fetchGradeDistData]);

/*
* Create an array of objects to feed into the professor dropdown menu.
* @return an array of JSON objects recording professor's names
*/
const createProfEntries = useCallback(() => {
const professors: Set<string> = new Set();
const result: Entry[] = [];

gradeDistData.forEach((match) => match.instructors.forEach((prof) => professors.add(prof)));

Array.from(professors)
.sort((a, b) => a.localeCompare(b))
.forEach((professor) => result.push({ value: professor, text: professor }));

setProfEntries(result);
setCurrentProf(result[0].value);
}, [gradeDistData]);

/*
* Create an array of objects to feed into the course dropdown menu.
* @return an array of JSON objects recording course's names
*/
const createCourseEntries = useCallback(() => {
const courses: Set<string> = new Set();
const result: Entry[] = [];

gradeDistData.forEach((match) => courses.add(match.department + ' ' + match.courseNumber));

Array.from(courses)
.sort((a, b) => a.localeCompare(b))
.forEach((course) => result.push({ value: course, text: course }));

setCourseEntries(result);
setCurrentCourse(result[0].value);
}, [gradeDistData]);

// update list of professors/courses when new course/professor is detected
useEffect(() => {
Expand All @@ -74,20 +111,13 @@ const GradeDist: FC<GradeDistProps> = (props) => {
createCourseEntries();
}
}
}, [gradeDistData]);

// update list of quarters when new professor/course is chosen
useEffect(() => {
if ((currentProf || currentCourse) && gradeDistData.length !== 0) {
createQuarterEntries();
}
}, [currentProf, currentCourse]);
}, [gradeDistData, createCourseEntries, createProfEntries, props.course, props.professor]);

/*
* Create an array of objects to feed into the quarter dropdown menu.
* @return an array of JSON objects recording each quarter
*/
const createQuarterEntries = () => {
const createQuarterEntries = useCallback(() => {
const quarters: Set<string> = new Set();
const result: Entry[] = [{ value: 'ALL', text: 'All Quarters' }];

Expand Down Expand Up @@ -122,43 +152,14 @@ const GradeDist: FC<GradeDistProps> = (props) => {
}),
);
setCurrentQuarter(result[0].value);
};
}, [currentCourse, currentProf, gradeDistData, props.course, props.professor]);

/*
* Create an array of objects to feed into the professor dropdown menu.
* @return an array of JSON objects recording professor's names
*/
const createProfEntries = () => {
const professors: Set<string> = new Set();
const result: Entry[] = [];

gradeDistData.forEach((match) => match.instructors.forEach((prof) => professors.add(prof)));

Array.from(professors)
.sort((a, b) => a.localeCompare(b))
.forEach((professor) => result.push({ value: professor, text: professor }));

setProfEntries(result);
setCurrentProf(result[0].value);
};

/*
* Create an array of objects to feed into the course dropdown menu.
* @return an array of JSON objects recording course's names
*/
const createCourseEntries = () => {
const courses: Set<string> = new Set();
const result: Entry[] = [];

gradeDistData.forEach((match) => courses.add(match.department + ' ' + match.courseNumber));

Array.from(courses)
.sort((a, b) => a.localeCompare(b))
.forEach((course) => result.push({ value: course, text: course }));

setCourseEntries(result);
setCurrentCourse(result[0].value);
};
// update list of quarters when new professor/course is chosen
useEffect(() => {
if ((currentProf || currentCourse) && gradeDistData.length !== 0) {
createQuarterEntries();
}
}, [currentProf, currentCourse, createQuarterEntries, gradeDistData]);

/*
* Record what is in the quarter dropdown menu at the moment.
Expand Down
2 changes: 1 addition & 1 deletion site/src/component/SideInfo/SideInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const SideInfo: FC<SideInfoProps> = (props) => {
setHighestReview(sortedKeys[sortedKeys.length - 1]);
setLowestReview(sortedKeys[0]);
}
}, [reviews]);
}, [reviews, allToken, props.searchType]);

// sort by number of reviews for the dropdown
const sortedReviews = Object.keys(averageReviews);
Expand Down
4 changes: 2 additions & 2 deletions site/src/pages/RoadmapPage/RoadmapMultiplan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ const RoadmapMultiplan: FC = () => {
};

useEffect(() => {
document.title = `${allPlans.plans[currentPlanIndex].name} | PeterPortal`;
}, [currentPlanIndex]);
document.title = `${name} | PeterPortal`;
}, [name]);

return (
<div className="multi-plan-selector">
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/RoadmapPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const RoadmapPage: FC = () => {
dispatch(moveCourse(movePayload));
}
},
[coursebag, dispatch, roadmap],
[coursebag, dispatch, roadmap, addCourseToBag, removeCourseFromBag],
);

const onDragStart = useCallback(
Expand Down
Loading