Skip to content

armgit / my-yt

Public Imported from GitHub
0

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

JavaScript

refactor: query var as state and fetch params

Christian Feie77858b2fcce
diff --git a/client/components/search-videos.js b/client/components/search-videos.js
index 3b1e5a1..062102d 100644
--- a/client/components/search-videos.js
+++ b/client/components/search-videos.js
@@ -116,9 +116,10 @@ class SearchVideos extends HTMLElement {
this.querySelector('#excluded').disabled = false
}
- window.history.pushState({}, '', `?filter=${encodeURIComponent(searchTerm)}${excluded ? '&excluded=true' : ''}${downloaded ? '&downloaded=true' : ''}${ignored ? '&ignored=true' : ''}${summarized ? '&summarized=true' : ''}`)
+ const query = `?filter=${encodeURIComponent(searchTerm)}${excluded ? '&excluded=true' : ''}${downloaded ? '&downloaded=true' : ''}${ignored ? '&ignored=true' : ''}${summarized ? '&summarized=true' : ''}`
+ window.history.pushState({}, '', query)
- fetch(`/api/videos?filter=${encodeURIComponent(searchTerm)}${excluded ? '&excluded=true' : ''}${downloaded ? '&downloaded=true' : ''}${ignored ? '&ignored=true' : ''}${summarized ? '&summarized=true' : ''}`)
+ fetch(`/api/videos${query}`)
.then(res => res.json())
.then((videos) => {
const $videosContainer = document.querySelector(this.dataset.videosContainer || '.main-videos-container')