From b553c3108290587ae4ec6a52d04539aad5708947 Mon Sep 17 00:00:00 2001 From: Cerys Date: Tue, 28 Jan 2025 11:04:07 +0000 Subject: [PATCH] design updates for the voting system --- Pages/tune/uuid.php | 24 ++++++++++++++++ Public/API/V1/RateTune.php | 1 + Public/Static/CSS/Elements/Rating.css | 40 ++++++++++++++++++++------- Templates/Pages/tune/uuid.html.twig | 20 ++++++++++++-- 4 files changed, 72 insertions(+), 13 deletions(-) diff --git a/Pages/tune/uuid.php b/Pages/tune/uuid.php index c7f7ad3..0fad20f 100644 --- a/Pages/tune/uuid.php +++ b/Pages/tune/uuid.php @@ -1,6 +1,8 @@ RunSelect( + queryBuilder: SQLQueryBuilderWrapper::SELECT( + table: 'TuneRatings', + ) + ->cols(cols: [ + 'Rating' + ]) + ->where(cond: 'CreatedBy=:__user_id__') + ->where(cond: 'TuneID=:__tune_id__') + ->bindValue(name: '__user_id__', value: SessionWrapper::Get(SessionElement::USER_ID)) + ->bindValue(name: '__tune_id__', value: $_GET["tune-id"]) +); +if($myVote == []) + $myVote = 0; +else +{ + $myVote = $myVote[0]['Rating']; +} + + TwigWrapper::RenderTwig( target: "Pages/tune/uuid.html.twig", arguments: [ "TuneDetails"=>$tuneDetails, "Dances"=>$dances, + "MyVote"=>$myVote, ] ); diff --git a/Public/API/V1/RateTune.php b/Public/API/V1/RateTune.php index 6c3f4bc..be0a141 100644 --- a/Public/API/V1/RateTune.php +++ b/Public/API/V1/RateTune.php @@ -81,6 +81,7 @@ $tuneRatings = $db->RunSelect( ); echo json_encode([ + "NewVoteValue" => intval($ratingValue), "LikeCount" => intval($tuneRatings[0]["Likes"]), "DislikeCount" => intval($tuneRatings[0]["Dislikes"]), ]); diff --git a/Public/Static/CSS/Elements/Rating.css b/Public/Static/CSS/Elements/Rating.css index 39b1c60..7d8dfb1 100644 --- a/Public/Static/CSS/Elements/Rating.css +++ b/Public/Static/CSS/Elements/Rating.css @@ -1,29 +1,49 @@ - +#RatingContainer { + text-align: center; + margin-top: 2rem; + font-family: Arial, sans-serif; +} .RatingButtons { display: flex; - gap: 1rem; justify-content: center; + gap: 1.5rem; margin-top: 1rem; } + #RatingContainer button { - background: none; + background-color: transparent; border: none; cursor: pointer; font-size: 2rem; - transition: transform 0.2s, color 0.2s; + padding: 0.5rem; + transition: transform 0.2s, color 0.2s, background-color 0.2s; + border-radius: 50%; } + #RatingContainer button:hover { - transform: scale(1.2); -} -#ThumbUp { - color: green; + transform: scale(1.3); + background-color: #f0f0f0; } -#ThumbDown { - color: red; + +#RatingContainer button.active { + transform: scale(1.3); + color: #0073e6; + background-color: #e0f7ff; } + .Counts { + display: flex; + justify-content: center; + gap: 1rem; margin-top: 1rem; font-size: 1.2rem; + color: #555; } +.count-item { + display: inline-flex; + align-items: center; + gap: 0.3rem; + font-weight: bold; +} diff --git a/Templates/Pages/tune/uuid.html.twig b/Templates/Pages/tune/uuid.html.twig index 9d002ec..16a6da5 100644 --- a/Templates/Pages/tune/uuid.html.twig +++ b/Templates/Pages/tune/uuid.html.twig @@ -15,6 +15,16 @@ API_GET('/V1/RateTune.php?tune-id={{ TuneDetails.ID }}&type='+type) .then(payload => { console.log(payload); + if(payload['NewVoteValue'] === -1) + { + document.getElementById('LikeButton').classList.remove('active'); + document.getElementById('DislikeButton').classList.add('active'); + } + else if(payload['NewVoteValue'] === 1) + { + document.getElementById('LikeButton').classList.add('active'); + document.getElementById('DislikeButton').classList.remove('active'); + } document.getElementById('LikeCount').innerHTML = payload['LikeCount']; document.getElementById('DislikeCount').innerHTML = payload['DislikeCount']; }) @@ -24,6 +34,8 @@ } + {{ MyVote|json_encode }} +
@@ -49,17 +61,19 @@

{{ "Rating"|translate }}

{% if _SESSION_.IS_LOGGED_IN %} - - + + {% else %} {{ "Log in to vote"|translate }} {% endif %}
+ | + 👎 {{ TuneDetails.Dislikes }} | 👍 {{ TuneDetails.Likes }} | - 👎 {{ TuneDetails.Dislikes }} + {{ TuneDetails.Bookmarks }} |