Skip to content

Commit

Permalink
Merge pull request #292 from UTDNebula/288-bug-handle-null-rmp-data
Browse files Browse the repository at this point in the history
288 bug handle null rmp data
  • Loading branch information
TyHil authored Nov 10, 2024
2 parents 47d354f + 7c725b8 commit c720d04
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 26 deletions.
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/basic-features/typescript for more information.
44 changes: 24 additions & 20 deletions src/components/common/CompareTable/compareTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,31 @@ function GradeOrRmpRow<T>({
<Typography className="text-base">{loadingFiller}</Typography>
</Skeleton>
)) ||
(value.state === 'done' && getValue(value.data) !== -1 && (
<Tooltip
title={`${name}: ${formatValue(getValue(value.data))}`}
placement="top"
>
<Typography
className="text-base inline rounded-full px-5 py-2 text-black"
style={{
backgroundColor: colorMidpoint(
goodValue,
badValue,
getValue(value.data),
),
}}
(value.state === 'done' &&
(name !== 'GPA'
? (value.data as RMPInterface).numRatings > 0
: true) && ( // do not display RMP data (non-GPA data) if there are no reviews
<Tooltip
title={`${name}: ${formatValue(getValue(value.data))}`}
placement="top"
>
{/*value.data is all the data past the state of loading, done, or error.
<Typography
className="text-base inline rounded-full px-5 py-2 text-black"
style={{
backgroundColor: colorMidpoint(
goodValue,
badValue,
getValue(value.data),
),
}}
>
{/*value.data is all the data past the state of loading, done, or error.
getValue returns the specific value from the data structure, like gpa.
formatValue makes it look pretty like 3.7216373 displaying as 3.72.*/}
{formatValue(getValue(value.data))}
</Typography>
</Tooltip>
)) ||
{formatValue(getValue(value.data))}
</Typography>
</Tooltip>
)) ||
null}
</TableCell>
))}
Expand Down Expand Up @@ -274,7 +277,8 @@ function GradeAndRmpRow({
</Typography>
</Skeleton>
)) ||
(rmp.state === 'done' && (
(rmp.state === 'done' && rmpValue == 0 && <CloseIcon />) ||
(rmp.state === 'done' && rmpValue != 0 && (
<Typography className="text-base inline">
{rmpValue}
</Typography>
Expand Down
11 changes: 6 additions & 5 deletions src/components/common/SearchResultsTable/searchResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,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 @@ -409,16 +410,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
23 changes: 23 additions & 0 deletions src/components/common/SingleProfInfo/singleProfInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@ function SingleProfInfo({ rmp }: Props) {
</Grid>
);
}
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}>
<Link
href={
'https://www.ratemyprofessors.com/professor/' + rmp.data.legacyId
}
target="_blank"
className="underline text-blue-600 hover:text-blue-800 visited:text-purple-600"
>
Visit Rate My Professors
</Link>
</Grid>
</Grid>
);
}
return (
<Grid container spacing={2} className="p-4">
<Grid item xs={6}>
Expand Down

0 comments on commit c720d04

Please sign in to comment.