From 77b30f279a893b0fe382374693e995929e1bc43c Mon Sep 17 00:00:00 2001 From: benjamin Date: Mon, 30 Oct 2023 12:29:06 -0700 Subject: [PATCH] update UI --- src/content/content.js | 49 +++++++++++++++++++++++++++--------------- src/content/styles.css | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 17 deletions(-) diff --git a/src/content/content.js b/src/content/content.js index d3ed34c..47aa4db 100644 --- a/src/content/content.js +++ b/src/content/content.js @@ -106,18 +106,25 @@ async function processCurrentRow(row) { ); log(profReviewList); $(row).children(".rmp").empty(); + + let hasNext = false; for (profReview of profReviewList) { if (profReview === null) { $(row).children(".rmp").first().append($("

").text("N/A")); continue; } + //check if comma is neccessary + const currentIndex = profReviewList.indexOf(profReview); + hasNext = profReviewList[currentIndex + 1] !== undefined && profReviewList[currentIndex + 1] !== null; + // Insert score into DOM - let HydratedProfScoreComp = ProfScoreComp(profReview); + //let HydratedProfScoreComp = ProfScoreComp(profReview); + let HydratedProfScoreComp = ProfReviewComp(profReview, hasNext); $(row).children(".rmp").first().append(HydratedProfScoreComp); // Decorate profName - decorateInstructorDiv(instructorDiv, profReview); + //decorateInstructorDiv(instructorDiv, profReview); } } @@ -206,7 +213,7 @@ function ProfScoreComp(profData) { return divFormat; } -function ProfReviewComp(profData) { +function ProfReviewComp(profData, hasNext) { if (profData.numRatings == 0) { return `N/A`; } @@ -215,24 +222,32 @@ function ProfReviewComp(profData) { if (profData.avgRating < 2.5) { colorCode = "#FF9C9C"; } else if (profData.avgRating < 3.5) { - colorCode = "#FFFF68"; + colorCode = "#FFD700"; } else { - colorCode = "#68FFBE"; + colorCode = "#03C03C"; } + + if(hasNext){ + addComma = ", " + }else{ + addComma = " " + } + const divFormat = ` -

- -
${ - profData.avgRating - }/5 -
-
Average difficulty: ${profData.avgDifficulty}
-
${profData.wouldTakeAgainPercent.toFixed(0)}% would take again
-
${profData.numRatings} rating(s)
+
`; +
+
${profData.name} ${profData.avgRating}/5
+
${profData.avgDifficulty} difficulty
+
${profData.wouldTakeAgainPercent.toFixed(0)}% would take again
+
${profData.numRatings} rating(s)
+
+
+ `; return divFormat; } diff --git a/src/content/styles.css b/src/content/styles.css index c3d8c23..3af1c0e 100644 --- a/src/content/styles.css +++ b/src/content/styles.css @@ -4,3 +4,47 @@ padding-left: 10px; } } + + +.prof-container { + position: relative; + display: inline-block; + } + + .prof-info { + margin-left: 15px; + padding: 10px; + position: absolute; + top: 0; + left: 100%; + opacity: 0; + background-color: white; + transition: opacity .4s ease; + pointer-events: none; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); + border-radius: 5px; + font-family: 'Arial', sans-serif; + width: 180px; + height: auto; + + } + + .prof-container:hover .prof-info { + background-color: white; + transition: opacity .4s ease; + opacity: 1; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); + z-index: 1; + } + + .prof-container:hover .prof-anchor { + background-color: rgba(246, 243, 243, 0.995); + } + + .prof-namebox{ + margin-bottom: 3px; + padding: 2px; + padding-left: 4px; + box-shadow: 0 0 2px rgba(0, 0, 0, 0.5); + border-radius: 5px; + } \ No newline at end of file