Skip to content

Commit

Permalink
Show nothing while grade dist data is being fetched. Show error if th…
Browse files Browse the repository at this point in the history
…e fetch fails
  • Loading branch information
js0mmer committed May 7, 2023
1 parent 8b0328c commit 98ecf93
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions site/src/component/GradeDist/GradeDist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ const GradeDist: FC<GradeDistProps> = (props) => {
.then(res => {
setGradeDistData(res.data);
}).catch(error => {
setGradeDistData([]);
console.error(error.response);
});
}

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

Expand Down Expand Up @@ -234,11 +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>
<>
Error: could not retrieve grade distribution data.
</div>
</>
);
}
}
Expand Down

0 comments on commit 98ecf93

Please sign in to comment.