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

Fix search page crash #530

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions site/src/component/GradeDist/GradeDist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const GradeDist: FC<GradeDistProps> = (props) => {
* @param props attributes received from the parent element
*/

const [gradeDistData, setGradeDistData] = useState<GradesRaw>(null!);
const [gradeDistData, setGradeDistData] = useState<GradesRaw>();
const [chartType, setChartType] = useState<ChartTypes>('bar');
const [currentQuarter, setCurrentQuarter] = useState('');
const [currentProf, setCurrentProf] = useState('');
const [profEntries, setProfEntries] = useState<Entry[]>(null!);
const [profEntries, setProfEntries] = useState<Entry[]>();
const [currentCourse, setCurrentCourse] = useState('');
const [courseEntries, setCourseEntries] = useState<Entry[]>(null!);
const [quarterEntries, setQuarterEntries] = useState<Entry[]>(null!);
const [courseEntries, setCourseEntries] = useState<Entry[]>();
const [quarterEntries, setQuarterEntries] = useState<Entry[]>();

const fetchGradeDistData = useCallback(() => {
let requests: Promise<GradesRaw>[];
Expand Down Expand Up @@ -74,7 +74,7 @@ const GradeDist: FC<GradeDistProps> = (props) => {
const professors: Set<string> = new Set();
const result: Entry[] = [];

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

Array.from(professors)
.sort((a, b) => a.localeCompare(b))
Expand All @@ -92,7 +92,7 @@ const GradeDist: FC<GradeDistProps> = (props) => {
const courses: Set<string> = new Set();
const result: Entry[] = [];

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

Array.from(courses)
.sort((a, b) => a.localeCompare(b))
Expand Down Expand Up @@ -121,7 +121,7 @@ const GradeDist: FC<GradeDistProps> = (props) => {
const quarters: Set<string> = new Set();
const result: Entry[] = [{ value: 'ALL', text: 'All Quarters' }];

gradeDistData
gradeDistData!
.filter((entry) => {
if (props.course && entry.instructors.includes(currentProf)) {
return true;
Expand Down Expand Up @@ -156,7 +156,7 @@ const GradeDist: FC<GradeDistProps> = (props) => {

// update list of quarters when new professor/course is chosen
useEffect(() => {
if ((currentProf || currentCourse) && gradeDistData.length !== 0) {
if ((currentProf || currentCourse) && gradeDistData && gradeDistData.length !== 0) {
js0mmer marked this conversation as resolved.
Show resolved Hide resolved
createQuarterEntries();
}
}, [currentProf, currentCourse, createQuarterEntries, gradeDistData]);
Expand Down Expand Up @@ -230,7 +230,7 @@ const GradeDist: FC<GradeDistProps> = (props) => {
</Grid.Row>
);

if (gradeDistData !== null && gradeDistData.length !== 0) {
if (gradeDistData && gradeDistData.length !== 0) {
const graphProps = {
gradeData: gradeDistData,
quarter: currentQuarter,
Expand Down
Loading