Skip to content

Commit

Permalink
Merge pull request #284 from icssc/jacob/grade-dist-crash
Browse files Browse the repository at this point in the history
Professor page/grade distribution crash
  • Loading branch information
js0mmer authored May 7, 2023
2 parents 4a0b1f4 + 98ecf93 commit 6372ff0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
8 changes: 6 additions & 2 deletions api/src/controllers/professors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ router.post('/api/batch', (req: Request<{}, {}, { professors: string[] }>, res)
router.get('/api/grades/:name', function (req, res, next) {
let r = fetch(process.env.PUBLIC_API_URL + 'grades/raw?instructor=' + encodeURIComponent(req.params.name));

r.then((response) => response.json())
.then((data) => res.send(data))
let status = 200;

r.then((response) => {
status = response.status;
return response.json();
}).then((data) => res.status(status).send(data))
});

export default router;
23 changes: 11 additions & 12 deletions site/src/component/GradeDist/GradeDist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,15 @@ const GradeDist: FC<GradeDistProps> = (props) => {
})
.then(res => {
setGradeDistData(res.data);
}).catch(error => {
setGradeDistData([]);
console.error(error.response);
});
}

// initial request to get grade dist data
// reset any data from a previous course or professor, get new data for course or professor
useEffect(() => {
if (gradeDistData == null) {
fetchGradeDistData();
}
})

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

Expand Down Expand Up @@ -239,10 +235,13 @@ const GradeDist: FC<GradeDistProps> = (props) => {
</Grid.Row>
</div>
);
} else {
} else if (gradeDistData == null) { // null if still fetching, don't display anything while it still loads
return null;
} else { // gradeDistData is empty, did not receive any data from API call or received an error, display an error message
return (
<div>
</div>
<>
Error: could not retrieve grade distribution data.
</>
);
}
}
Expand Down

0 comments on commit 6372ff0

Please sign in to comment.