Skip to content
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

✅[outreachy] Registry : Add to favorites #5447 #5451

Closed
wants to merge 9 commits into from
30 changes: 30 additions & 0 deletions assets/js/addToFavorites.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
document.addEventListener('DOMContentLoaded', function () {
let favorites = JSON.parse(localStorage.getItem('favorites')) || [];

document.querySelectorAll('.favorite-btn').forEach(function (button) {
const registryId = button.getAttribute('data-registry-id');

if (favorites.includes(registryId)) {
button.innerHTML = '<i class="fa-solid fa-star"></i> Remove from Favorites';
button.classList.add('btn-success');
button.classList.remove('btn-outline-primary');
}

button.addEventListener('click', function () {
if (favorites.includes(registryId)) {
favorites = favorites.filter((id) => id !== registryId);
localStorage.setItem('favorites', JSON.stringify(favorites));
button.innerHTML =
'<i class="fa-regular fa-star"></i> Add to favorites';
button.classList.add('btn-outline-primary');
button.classList.remove('btn-success');
} else {
favorites.push(registryId);
localStorage.setItem('favorites', JSON.stringify(favorites));
button.innerHTML = '<i class="fa-solid fa-star"></i> Remove from Favorites';
button.classList.add('btn-success');
button.classList.remove('btn-outline-primary');
}
});
});
});
24 changes: 24 additions & 0 deletions assets/js/registrySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,27 @@ function parseUrlParams() {
selectedLanguage = urlParams.get('language') || 'all';
selectedComponent = urlParams.get('component') || 'all';
}

document.addEventListener('DOMContentLoaded', function () {
const filterBtn = document.getElementById('filter-favorites-btn');
const registryItems = document.querySelectorAll('.registry-entry');

filterBtn.addEventListener('click', function () {
let favorites = JSON.parse(localStorage.getItem('favorites')) || [];

if (filterBtn.textContent.includes('Show Favorites')) {
registryItems.forEach(function (item) {
const registryId = item.getAttribute('data-registry-id');
if (!favorites.includes(registryId)) {
item.style.display = 'none';
}
});
filterBtn.textContent = 'Show All';
} else {
registryItems.forEach(function (item) {
item.style.display = '';
});
filterBtn.textContent = 'Show Favorites';
}
});
});
7 changes: 7 additions & 0 deletions layouts/partials/ecosystem/registry/entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ <h6><i class="fa-solid fa-forward"></i> Quick Install</h6>
{{ $demoUrl := printf "href=%q" (printf .) | safeHTMLAttr -}}
<a {{ $demoUrl }} target="_blank" rel="noopener" class="card-link"><i class="fa-solid fa-shapes" aria-hidden="true"></i>&nbsp;Demo Service</a>
{{- end -}}
<!-- Add to Favorites Button -->
<div class="text-end">
<button class="btn btn-link p-0 favorite-btn" data-registry-id="{{ ._key }}">
<i class="fa-regular fa-star"></i> Add to favorites
</button>
</div>
</div>
</li>
{{ end -}}
{{ partial "script.html" (dict "src" "js/addToFavorites.js") -}}
5 changes: 5 additions & 0 deletions layouts/shortcodes/ecosystem/registry/search-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
<button type="button" class="btn btn-outline-danger"
onclick="document.getElementById('input-s').value = ''; document.getElementById('input-language').value = 'all';document.getElementById('input-component').value = 'all';document.getElementById('searchForm').submit();">Reset</button>

<!-- Show Favorites Button -->
<button type="button" id="filter-favorites-btn" class="btn" style="border-color: #6a0dad; color: #6a0dad;">
Show Favorites
</button>

<button class="btn btn-outline-secondary dropdown-toggle" id="languageDropdown" type="button"
data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Language</button>
<div class="dropdown-menu" id="languageFilter">
Expand Down
2 changes: 1 addition & 1 deletion themes/docsy
Loading