Skip to content

Commit

Permalink
Changes for null data
Browse files Browse the repository at this point in the history
For #68 and #76
  • Loading branch information
TyHil committed Dec 15, 2024
1 parent df8e1f0 commit ee7a23f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/CourseOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CourseOverview = ({ header, grades }: CourseOverviewProps) => {
const isCourse = typeof header !== 'string';
return (
<div className="flex flex-col items-center gap-2">
<p className="text-2xl font-bold">
<p className="text-2xl font-bold text-center">
{isCourse ? searchQueryLabel(header) : header}
</p>
{isCourse && (
Expand Down
11 changes: 6 additions & 5 deletions src/components/SearchResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ function Row({
<Rating sx={{ fontSize: 25 }} readOnly />
</Skeleton>
)) ||
(rmp.state === 'done' && (
(rmp.state === 'done' && rmp.data.numRatings == 0 && <></>) ||
(rmp.state === 'done' && rmp.data.numRatings != 0 && (
<Tooltip
title={'Professor rating: ' + rmp.data.avgRating}
placement="top"
Expand Down Expand Up @@ -331,16 +332,16 @@ const SearchResultsTable = ({
const bRmp = rmp[searchQueryLabel(convertToProfOnly(b))];
//drop loading/error rows to bottom
if (
(!aRmp || aRmp.state !== 'done') &&
(!bRmp || bRmp.state !== 'done')
(!aRmp || aRmp.state !== 'done' || aRmp.data.numRatings == 0) &&
(!bRmp || bRmp.state !== 'done' || bRmp.data.numRatings == 0)
) {
// If both aRmp and bRmp are not done, treat them as equal and return 0
return 0;
}
if (!aRmp || aRmp.state !== 'done') {
if (!aRmp || aRmp.state !== 'done' || aRmp.data.numRatings == 0) {
return 9999;
}
if (!bRmp || bRmp.state !== 'done') {
if (!bRmp || bRmp.state !== 'done' || bRmp.data.numRatings == 0) {
return -9999;
}
const aRating = aRmp?.data?.avgRating ?? 0; // Fallback to 0 if undefined
Expand Down
37 changes: 34 additions & 3 deletions src/components/SingleProfInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ function SingleProfInfo({ rmp }: Props) {
);
}

if (rmp.data.numRatings == 0) {
return (
<Grid container spacing={2} className="p-4">
<Grid item xs={6}>
<p className="text-xl font-bold">
{rmp.data.numRatings.toLocaleString()}
</p>
<p>Ratings given</p>
</Grid>
<Grid item xs={12}>
<a
href={
'https://www.ratemyprofessors.com/professor/' + rmp.data.legacyId
}
target="_blank"
className="underline text-blue-600 hover:text-blue-800 visited:text-purple-600"
rel="noreferrer"
>
Visit Rate My Professors
</a>
</Grid>
</Grid>
);
}

const topTags = rmp.data.teacherRatingTags.sort(
(a, b) => b.tagCount - a.tagCount,
);
Expand All @@ -61,11 +86,15 @@ function SingleProfInfo({ rmp }: Props) {
return (
<Grid container spacing={2} className="p-4">
<Grid item xs={6}>
<p className="text-xl font-bold">{rmp.data.avgRating}</p>
<p className="text-xl font-bold">
{rmp.data.avgRating > 0 ? rmp.data.avgRating : 'N/A'}
</p>
<p>Professor rating</p>
</Grid>
<Grid item xs={6}>
<p className="text-xl font-bold">{rmp.data.avgDifficulty}</p>
<p className="text-xl font-bold">
{rmp.data.avgDifficulty > 0 ? rmp.data.avgDifficulty : 'N/A'}
</p>
<p>Difficulty</p>
</Grid>
<Grid item xs={6}>
Expand All @@ -76,7 +105,9 @@ function SingleProfInfo({ rmp }: Props) {
</Grid>
<Grid item xs={6}>
<p className="text-xl font-bold">
{rmp.data.wouldTakeAgainPercent.toFixed(0) + '%'}
{rmp.data.wouldTakeAgainPercent > 0
? rmp.data.wouldTakeAgainPercent.toFixed(0) + '%'
: 'N/A'}
</p>
<p>Would take again</p>
</Grid>
Expand Down

0 comments on commit ee7a23f

Please sign in to comment.