Skip to content

Commit

Permalink
Add favorite count on builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Pansysk75 committed Dec 31, 2023
1 parent 3dbed30 commit 943a2e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions web-app/src/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ class FavoritesManager {
const icon = button.children[0];
icon.style["font-variation-settings"] = `"FILL" ${buildId in this.favorites ? 1 : 0}`;
}

updateFavoriteCount(button) {
const build_id = button.value;
const parent = button.closest(".builds-element");
const favoriteCount = parent.querySelector(".times_added_to_favorites");
const current_count = favoriteCount.innerHTML;
// If not in users favorites, value must have been decremented
if (build_id in this.favorites) {
favoriteCount.innerHTML = parseInt(current_count) + 1;
} else {
favoriteCount.innerHTML = parseInt(current_count) - 1;
}
}
}

function onFavoriteButtonClick(event) {
Expand All @@ -71,6 +84,7 @@ function onFavoriteButtonClick(event) {
favoritesManager.toggleFavorite(buildId)
.then(() => {
favoritesManager.updateFavoriteButton(this);
favoritesManager.updateFavoriteCount(this);
})
.catch(error => {
console.error(`Error toggling favorite for buildId ${buildId}:`, error);
Expand Down
3 changes: 3 additions & 0 deletions web-app/views/builds.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
</strong>
(out of <%= builds[i].number_of_ratings %> ratings)
</div>
<div>
<span class="times_added_to_favorites"><%= builds[i].times_added_to_favorites %></span> users favorited this build
</div>
</div>
<% } %>
Expand Down

0 comments on commit 943a2e2

Please sign in to comment.