A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
fix: handle empty state when updating videos-container
Christian Fei8e34b9e39e5e
diff --git a/client/lib/router.js b/client/lib/router.jsindex 16a5072..63e25b8 100644--- a/client/lib/router.js+++ b/client/lib/router.js@@ -23,13 +23,14 @@ const routes = {const channels = await fetch('/api/channels').then(res => res.json())document.querySelector('channels-list').dataset['list'] = JSON.stringify(channels.map(c => c.name).filter(Boolean))+ document.querySelector('empty-state').dataset['hasChannels'] = channels.length > 0+ handleEmptyState()- if (videos.length === 0) {- document.querySelector('empty-state').style.display = ''- document.querySelector('empty-state').dataset['hasChannels'] = channels.length > 0- } else {- document.querySelector('empty-state').style.display = 'none'- }+ new MutationObserver((mutationList, observer) => {+ for (const mutation of mutationList) {+ handleEmptyState()+ }+ }).observe($videosContainer, { attributes: false, childList: true, subtree: true })applyShowThumbnails(store.get(store.showThumbnailsKey))applyShowBigPlayer(store.get(store.showBigPlayerKey))@@ -99,3 +100,11 @@ function handleRoute() {routes['/404'].initialize && routes['/404'].initialize()}}++function handleEmptyState () {+ if (document.querySelectorAll('video-element').length === 0) {+ document.querySelector('empty-state').style.display = ''+ } else {+ document.querySelector('empty-state').style.display = 'none'+ }+}\ No newline at end of filediff --git a/lib/server.js b/lib/server.jsindex cd54317..4138649 100644--- a/lib/server.js+++ b/lib/server.js@@ -346,10 +346,12 @@ function diskUsageHandler(req, res, repo) {.reduce((total, video) => {try {const files = fs.globSync(`./data/videos/${video.id}*`)- return total + files.reduce((acc, file) => {+ total += files.reduce((acc, file) => {const filesize = fs.statSync(file).size / Math.pow(10, 9)return acc + filesize}, 0)+ repo.setVideoDownloaded(video.id, false)+ return total} catch (err) {console.error(err)return total