Merge pull request #238 from teaxyz/no-results-found

'No Results Found' for Package Section
This commit is contained in:
Neil 2022-12-22 12:59:12 +08:00 committed by GitHub
commit 0e9d11f29b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View file

@ -28,4 +28,6 @@ exclude = [
"file:///home/runner/work/www/www/public/+github.com/rhash/RHash", "file:///home/runner/work/www/www/public/+github.com/rhash/RHash",
"file:///home/runner/work/www/www/public/+github.com/rhash/RHash", "file:///home/runner/work/www/www/public/+github.com/rhash/RHash",
"https://app.tea.xyz/api/signups", # can take a little too long, and no reason to hammer here. "https://app.tea.xyz/api/signups", # can take a little too long, and no reason to hammer here.
"https://unicode.org/",
"https://gnome.org/"
] ]

View file

@ -0,0 +1,21 @@
<hr>
<section id="noResult" class="no-results">
<div class="container black-bg">
<div class="row">
<div class="col two-boxes-up two-boxes-down">
<h4 class="text-center">No results found :(</h4>
<p class="text-center">Try refining your search term.</p>
</div>
</div>
</div>
</section>
<hr>
<style>
.no-results {
display: none;
}
.no-results.show {
display: block;
}
</style>

View file

@ -24,6 +24,7 @@
{{- partial "package-thumbnail.html" .}} {{- partial "package-thumbnail.html" .}}
{{ end }} {{ end }}
</div> </div>
{{- partial "no-results-found.html" }}
</div> </div>
</div> </div>
<hr> <hr>
@ -120,6 +121,7 @@
const onSearch = debounce(() => { const onSearch = debounce(() => {
const searchInput = document.getElementById('searchTermDesktop'); const searchInput = document.getElementById('searchTermDesktop');
const noResult = document.getElementById('noResult');
if (searchInput.value) { if (searchInput.value) {
const term = searchInput.value; const term = searchInput.value;
const packages = getPackageThumbs(); const packages = getPackageThumbs();
@ -130,16 +132,28 @@
}); });
const grid = document.getElementById('packageGrid'); const grid = document.getElementById('packageGrid');
grid.textContent = ''; grid.textContent = '';
let searchCount = 0;
for(const sp of sortedPackages) { for(const sp of sortedPackages) {
const score = getMatchScore(term, sp.dataset); const score = getMatchScore(term, sp.dataset);
if (score > 20) { if (score > 20) {
sp.classList.remove('hidden'); sp.classList.remove('hidden');
searchCount++;
} else { } else {
sp.classList.add('hidden'); sp.classList.add('hidden');
} }
grid.appendChild(sp); grid.appendChild(sp);
} }
if (searchCount) {
loadMoreSection.classList.remove('hidden');
noResult.classList.remove('show');
} else {
loadMoreSection.classList.add('hidden');
noResult.classList.add('show');
}
} else { } else {
noResult.classList.remove('show');
sortPackages(); sortPackages();
} }
}, 300); }, 300);