Skip to content

Commit 7ef8417

Browse files
committed
feat: add dynamic favorites count badge
1 parent 4c51831 commit 7ef8417

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

web-app/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@
150150
</button>
151151
<button aria-selected="false" class="sidebar-tab" data-category="favorites" role="tab" tabindex="-1">
152152
<span class="sidebar-icon"><svg data-lucide="star"></svg></span>
153-
<span class="sidebar-label">My Favorites</span>
153+
<span class="sidebar-label">
154+
My Favorites
155+
<span id="favoritesCountBadge">0</span>
156+
</span>
154157
</button>
155158
<button aria-selected="false" class="sidebar-tab" data-category="playground" role="tab" tabindex="-1">
156159
<span class="sidebar-icon"><svg data-lucide="terminal"></svg></span>

web-app/js/main.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,14 @@ document.addEventListener("DOMContentLoaded", function () {
14331433
window.closeProjectSafe = closeProjectSafe;
14341434
window.setMainInert = setMainInert;
14351435

1436+
function updateFavoritesCountBadge() {
1437+
const badge = document.getElementById("favoritesCountBadge");
1438+
if (!badge) return;
1439+
1440+
const favorites = JSON.parse(localStorage.getItem("favorites") || "[]");
1441+
badge.textContent = `(${favorites.length})`;
1442+
}
1443+
14361444
/* ═══════════════════════════════════════════════════════════════
14371445
WIRE PROJECT CARDS
14381446
═══════════════════════════════════════════════════════════════ */
@@ -1474,6 +1482,7 @@ document.addEventListener("DOMContentLoaded", function () {
14741482
}
14751483
}
14761484
localStorage.setItem("favorites", JSON.stringify(favs));
1485+
updateFavoritesCountBadge();
14771486
});
14781487

14791488
var cardActions = card.querySelector(".card-actions");
@@ -1542,6 +1551,8 @@ document.addEventListener("DOMContentLoaded", function () {
15421551

15431552
projectCards.forEach(wireProjectCard);
15441553

1554+
updateFavoritesCountBadge();
1555+
15451556
window.updateRecentlyViewed = function () {
15461557
var grid = document.getElementById("recentlyViewedGrid");
15471558
var section = document.getElementById("recentlyViewedSection");

0 commit comments

Comments
 (0)