From 1f05dc8f78683addf65df8f8ebc1f7db29b27316 Mon Sep 17 00:00:00 2001 From: Moyasee Date: Sat, 4 Oct 2025 20:12:01 +0300 Subject: [PATCH] Feat: Rating score display redesign, Rating choosing redesign, added avg rating on the game page --- src/locales/en/translation.json | 3 ++ .../game-details/game-details-content.tsx | 43 ++++++++++++++---- .../src/pages/game-details/game-details.scss | 45 ++++++++++++++++++- .../pages/game-details/sidebar/sidebar.scss | 5 +-- .../pages/game-details/sidebar/sidebar.tsx | 11 +++++ src/shared/html-sanitizer.ts | 4 +- 6 files changed, 95 insertions(+), 16 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 22bb9380..b54fe2fb 100755 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -200,6 +200,7 @@ "stats": "Stats", "download_count": "Downloads", "player_count": "Active players", + "rating_count": "Rating", "download_error": "This download option is not available", "download": "Download", "executable_path_in_use": "Executable already in use by \"{{game}}\"", @@ -220,6 +221,8 @@ "sort_lowest_score": "Lowest Score", "sort_most_voted": "Most Voted", "rating": "Rating", + "rating_stats": "Rating", + "select_rating": "Select Rating", "submit_review": "Submit Review", "submitting": "Submitting...", "loading_reviews": "Loading reviews...", diff --git a/src/renderer/src/pages/game-details/game-details-content.tsx b/src/renderer/src/pages/game-details/game-details-content.tsx index 28321f1e..03959506 100644 --- a/src/renderer/src/pages/game-details/game-details-content.tsx +++ b/src/renderer/src/pages/game-details/game-details-content.tsx @@ -24,6 +24,14 @@ import { useUserDetails, useLibrary, useDate } from "@renderer/hooks"; import { useSubscription } from "@renderer/hooks/use-subscription"; import "./game-details.scss"; +// Helper function to get score color class +const getScoreColorClass = (score: number): string => { + if (score >= 0 && score <= 3) return "game-details__review-score--red"; + if (score >= 4 && score <= 6) return "game-details__review-score--yellow"; + if (score >= 7 && score <= 10) return "game-details__review-score--green"; + return ""; +}; + export function GameDetailsContent() { const heroRef = useRef(null); const navigate = useNavigate(); @@ -103,7 +111,7 @@ export function GameDetailsContent() { // Reviews state management const [reviews, setReviews] = useState([]); const [reviewsLoading, setReviewsLoading] = useState(false); - const [reviewScore, setReviewScore] = useState(5); + const [reviewScore, setReviewScore] = useState(null); const [submittingReview, setSubmittingReview] = useState(false); const [reviewCharCount, setReviewCharCount] = useState(0); const MAX_REVIEW_CHARS = 1000; @@ -302,6 +310,7 @@ export function GameDetailsContent() { if ( !objectId || !reviewHtml.trim() || + reviewScore === null || submittingReview || reviewCharCount > MAX_REVIEW_CHARS ) { @@ -322,7 +331,7 @@ export function GameDetailsContent() { console.log("Review submitted successfully"); editor?.commands.clearContent(); - setReviewScore(5); + setReviewScore(null); await loadReviews(true); // Reload reviews after submission setShowReviewForm(false); // Hide the review form after successful submission setShowReviewPrompt(false); // Hide the prompt banner @@ -606,10 +615,14 @@ export function GameDetailsContent() { - + onClick={() => editor?.commands.focus()} + > + +
@@ -618,12 +631,23 @@ export function GameDetailsContent() { {t("rating")}