1
0
Fork 0
mirror of https://gitlab.com/Alamantus/Readlebee.git synced 2025-03-25 12:50:44 +01:00
Readlebee/app/views/partials/starRating.js
Robbie Antenesse 896dc7b869 Add star rating icons and review count to search results
These are currently randomized until database support is added
2019-09-11 22:42:01 -06:00

19 lines
No EOL
528 B
JavaScript

import html from 'choo/html';
export const starRating = (rating) => {
const wholeStars = Math.floor(rating);
const hasPartial = rating - wholeStars > 0;
const emptyStars = 5 - wholeStars - (hasPartial ? 1 : 0);
const stars = [];
for (let i = 0; i < wholeStars; i++) {
stars.push(html`<i class="icon-star"></i>`);
}
if (hasPartial) {
stars.push(html`<i class="icon-star-half"></i>`);
}
for (let i = 0; i < emptyStars; i++) {
stars.push(html`<i class="icon-star-empty"></i>`);
}
return stars;
}