A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
feat: consolidate state sse
Christian Feiaeba27b88911
diff --git a/client/components/video-element.js b/client/components/video-element.jsindex af2e97f..b8c2b53 100644--- a/client/components/video-element.js+++ b/client/components/video-element.js@@ -5,6 +5,8 @@ const store = new Store()class VideoElement extends HTMLElement {constructor () {super()+ this.downloadStartedText = '⚡️ Downloading..'+ this.summaryStartedText = '⚡️ Summarizing..'}connectedCallback () {@@ -15,7 +17,7 @@ class VideoElement extends HTMLElement {this.unregisterEvents()}static get observedAttributes() {- return ['data-data'];+ return ['data-data', 'data-summarizing', 'data-downloading'];}attributeChangedCallback(name, _, newValue) {@@ -23,6 +25,12 @@ class VideoElement extends HTMLElement {this.video = JSON.parse(this.dataset['data'])this.render()}+ if (name === 'data-summarizing') {+ this.querySelector('.action.summarize').innerText = this.summaryStartedText+ }+ if (name === 'data-downloading') {+ this.querySelector('.action.download').innerText = this.downloadStartedText+ }}render () {if (!this.video) return@@ -105,7 +113,7 @@ class VideoElement extends HTMLElement {downloadVideoHandler (event) {event.preventDefault()- const downloadStartedText = '⚡️ Download started'+ const downloadStartedText = '⚡️ Downloading..'let $downloadButton = event.target.classList.contains('.action') ? event.target : this.querySelector('.action.download')if ($downloadButton.innerText === downloadStartedText) returnelse $downloadButton.innerText = downloadStartedText@@ -138,7 +146,7 @@ class VideoElement extends HTMLElement {}summarizeVideoHandler (event) {event.preventDefault()- const summaryStartedText = '⚡️ summary started'+ const summaryStartedText = '⚡️ Summarizing..'if (event.target.innerText === summaryStartedText) returnevent.target.innerText = summaryStartedTextfetch('/api/summarize-video', {diff --git a/client/main.js b/client/main.jsindex 17de09f..bd3f210 100644--- a/client/main.js+++ b/client/main.js@@ -18,6 +18,15 @@ eventSource.onmessage = (message) => {$downloading.innerText = `Downloading: ${downloadingCount}`const summarizingCount = Object.keys(data.state.summarizing || {}).length$summarizing.innerText = `Summarizing: ${summarizingCount}`++ Object.keys(data.state.summarizing || {}).map((videoId) => {+ const $video = document.querySelector(`video-element[data-video-id="${videoId}"]`)+ if ($video) $video.dataset['summarizing'] = "true"+ })+ Object.keys(data.state.downloading || {}).map((videoId) => {+ const $video = document.querySelector(`video-element[data-video-id="${videoId}"]`)+ if ($video) $video.dataset['downloading'] = "true"+ })return}if (data.type === 'download-log-line' && data.line) {