Skip to content

Commit

Permalink
Asset page filtering (#734)
Browse files Browse the repository at this point in the history
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
  • Loading branch information
d-bucur and cart authored Aug 23, 2023
1 parent a0c8a46 commit 6c50953
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sass/pages/_assets.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,19 @@
.item-grid {
margin-bottom: 52px;
}

.assets-search {
margin-bottom: 20px;

&__input {
@include card;
font-size: 1.2rem;
padding: $asset-card-padding;
width: 100%;

&:focus-visible {
outline: none;
}
}
}
}
39 changes: 39 additions & 0 deletions static/assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const searchElement = document.querySelector('#assets-search')

searchElement.addEventListener("input", (_) => {
filterSearchTerms()
hideEmptySubSections()
hideEmptySections()
})

function filterSearchTerms() {
const searchTerms = searchElement.value.toLowerCase().split(' ')
for (const asset of document.querySelectorAll('.asset-card')) {
const fullText = asset.text.toLowerCase()
const searchMatch = searchTerms.every((term) => fullText.includes(term))
asset.parentElement.style.display = searchMatch ? 'block' : 'none'
}
}

function hideEmptySubSections() {
for (const itemGrid of document.querySelectorAll('.item-grid')) {
const cardInGrid = [...itemGrid.querySelectorAll('.asset-card')]
const areAllHidden = (cardInGrid.every((card) => card.parentElement.style.display === 'none'))
itemGrid.style.display = areAllHidden ? 'none' : 'grid'
itemGrid.previousElementSibling.style.display = areAllHidden ? 'none' : 'block'
}
}

function hideEmptySections() {
document.querySelectorAll('.asset-section').forEach(section => {
let nextElement = section.nextElementSibling
while (nextElement && !nextElement.classList.contains('asset-section')) {
if (nextElement.style.display !== 'none') {
section.style.display = 'block'
return
}
nextElement = nextElement.nextElementSibling
}
section.style.display = 'none'
})
}
8 changes: 8 additions & 0 deletions templates/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<div class="assets">
{{ assets_macros::init_svg() }}

<div class="assets-search">
<input class="assets-search__input" type="text" id="assets-search" placeholder="Search (ie: 0.11 MIT)">
</div>

<div class="assets-intro media-content">
A collection of third-party Bevy assets, plugins, learning resources, and apps made by the community. If you would like to
share what you're working on, <a href="https://github.com/bevyengine/bevy-assets">submit a pull request</a>!
Expand Down Expand Up @@ -62,4 +66,8 @@ <h3 class="asset-subsection" id="{{ section.title | slugify }}">
{% endfor %}
{% endfor %}
</div>

<script type="module">
import '/assets.js'
</script>
{% endblock %}

0 comments on commit 6c50953

Please sign in to comment.