Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript

feat: show filter results status

Christian Fei75fc9b07dbc0
diff --git a/client/components/search-videos.js b/client/components/search-videos.js
index cbeda7a..dd41d76 100644
--- a/client/components/search-videos.js
+++ b/client/components/search-videos.js
@@ -21,7 +21,13 @@ class SearchVideos extends HTMLElement {
}
searchHandler (event) {
event.preventDefault()
- const searchTerm = event.target.value.toLowerCase()
+ const searchTerm = event.target.value.trim().toLowerCase()
+ const $status = document.querySelector('#filter-results-status')
+ if (!searchTerm) {
+ if ($status) $status.innerText = ''
+ return console.log('no search term')
+ }
+ let filteredCount = 0
document.querySelectorAll('.video').forEach(video => {
const videoData = JSON.parse(video.dataset['data'])
if (
@@ -30,11 +36,15 @@ class SearchVideos extends HTMLElement {
|| videoData.channelName?.toLowerCase().includes(searchTerm)
) {
video.style.display = ''
+ filteredCount++
} else {
video.style.display = 'none'
}
})
-
+ if ($status) {
+ if (filteredCount > 0) $status.innerText = `Found ${filteredCount} videos`
+ else $status.innerText = `No videos found`
+ }
}
}
customElements.define('search-videos', SearchVideos)
diff --git a/client/index.html b/client/index.html
index 55bc899..3368ad1 100644
--- a/client/index.html
+++ b/client/index.html
@@ -20,7 +20,7 @@
<summary>Download Log</summary>
<div class="lines"></div>
</details>
-
+
<dialog id="summary">
<button id="close">X</button>
<div></div>
@@ -28,7 +28,8 @@
<template id="main-template">
<channels-list></channels-list>
- <div class="flex space-around">
+ <div id="filter-results-status"></div>
+ <div class="flex space-around p-1">
<button id="show-downloaded-videos">Downloaded videos</button>
<button id="show-summarized-videos">Summarized videos</button>
<button id="show-ignored-videos">Ignored videos</button>
diff --git a/client/main.css b/client/main.css
index 97971d0..3cf6c99 100644
--- a/client/main.css
+++ b/client/main.css
@@ -304,6 +304,12 @@ search-videos {
font-size: 1.1rem;
}
+
+#filter-results-status {
+ height: 2em;
+ padding: 0.5rem;
+}
+
details {
padding: 10px;
border: 5px solid #f7f7f7;