Improve behaviour of added packages in search box

This commit is contained in:
rubenwardy 2023-08-19 02:56:05 +01:00
parent 618a768f9a
commit b410ab3bcc
2 changed files with 6 additions and 2 deletions

@ -99,11 +99,15 @@ function updateResults(packages) {
document.getElementById("add_package_empty").style.display = packages.length === 0 ? "block" : "none";
const alreadyAdded = getAddedPackages();
packages.filter(pkg => !alreadyAdded.includes(`${pkg.author}/${pkg.name}`)).slice(0, 5).forEach(pkg => {
packages.slice(0, 5).forEach(pkg => {
const result = document.createElement("a");
result.classList.add("list-group-item");
result.classList.add("list-group-item-action");
result.innerText = `${pkg.title} by ${pkg.author}`;
if (alreadyAdded.includes(`${pkg.author}/${pkg.name}`)) {
result.classList.add("active");
result.innerHTML = "<i class='fas fa-check mr-3 text-success'></i>" + result.innerHTML;
}
result.addEventListener("click", () => addPackage(pkg));
results.appendChild(result);
});

@ -9,7 +9,7 @@
{% endblock %}
{% block scriptextra %}
<script src="/static/collection_editor.js?v=3"></script>
<script src="/static/collection_editor.js?v=4"></script>
{% endblock %}
{% block content %}