Skip to content

Commit

Permalink
Add the badge filter to search the DOM instead of making another request
Browse files Browse the repository at this point in the history
Making another request is very slow as it involves reloading the whole webpage to get the query filter from the URL
  • Loading branch information
AnishReddyRavula committed Nov 13, 2023
1 parent d43f629 commit f46c20a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions sharing_portal/static/sharing_portal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@
}
}
})();

function filter_artifacts(badge_filter) {
const filterInput = document.getElementById('cardFilter');
filterInput.value = ""; // reset the value in field
filterInput.value = badge_filter;
filterInput.dispatchEvent(new KeyboardEvent('keyup')); // trigger a keyup to apply filter
}
9 changes: 5 additions & 4 deletions sharing_portal/templates/sharing_portal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ <h1>Trovi</h1>
<h4>Badges</h4>
{% for badge in badges %}
<div>
<a href="{% url 'sharing_portal:index_all' %}?filter=badge:{{ badge.name|urlencode }}">
<button onclick="filter_artifacts('badge:{{ badge.name|urlencode }}')"
style="border:0.5px; padding-bottom:1 px; background-color: transparent;">
{% with 'images/'|add:badge.name|add:'-logo-small.png' as logo_static %}
<img src="{% static logo_static %}" alt="Small {{badge.name}} logo">
{% endwith %}
</a>
</button>
{% if badge.redirect_link %}
<a target="_blank" href="{{ badge.redirect_link }}">{{badge.description}}</a>
{% else %}
Expand All @@ -131,7 +132,7 @@ <h4>Badges</h4>
</div>
{% endfor %}
</div>

<div class="sidebarNav__separator">
<h4>Tags</h4>
{% for tag in tags %}
Expand All @@ -140,7 +141,7 @@ <h4>Tags</h4>
</div>
{% endfor %}
</div>

</div>
</div>
{% endblock %}

0 comments on commit f46c20a

Please sign in to comment.