_includes/appscms/extras/ratings.html in appscms-tools-theme-4.3.7 vs _includes/appscms/extras/ratings.html in appscms-tools-theme-4.3.8
- old
+ new
@@ -66,22 +66,31 @@
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
- ratingValue.innerText = data.rating
- count.innerText = data.count
+ console.log(data)
+
+ ratingValue.innerText = data.rating
+ count.innerText = data.count
+
+
})
.catch((error) => {
console.error('Error:', error);
});
}
const tool = '{{page.tool}}'
const fetchRating = async () => {
const data = await fetch(`https://ratingapi-main.netlify.app/.netlify/functions/api/v1/${tool}/rating`).then(res => res.json())
+ if (data.rating === "NaN") {
+ ratingValue.innerText = "5.00"
+ count.innerText = "1"
+ }
+ else{
ratingValue.innerText = data.rating
- count.innerText = data.votes
+ count.innerText = data.votes}
}
let ratingImg = document.querySelector('#rating-img');
ratingImg.addEventListener('load', (event) => {
fetchRating()
});
\ No newline at end of file