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: ignore video, updates sse

Christian Fei7b270b838375
diff --git a/client/components/video-element.js b/client/components/video-element.js
index cd1c4aa..f519203 100644
--- a/client/components/video-element.js
+++ b/client/components/video-element.js
@@ -189,11 +189,6 @@ class VideoElement extends HTMLElement {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: this.video.id }),
})
- .then(res => res.json())
- .then((ignored) => {
- this.video.ignored = ignored
- this.render()
- })
.catch((error) => {
console.error('Error ignoring video:', error)
this.render()
diff --git a/client/main.js b/client/main.js
index 6fd4204..1f115d9 100644
--- a/client/main.js
+++ b/client/main.js
@@ -61,6 +61,15 @@ eventSource.onmessage = (message) => {
})
return
}
+ if (data.type === 'ignored' && data.videoId && data.ignored !== undefined) {
+ ;[...document.querySelectorAll(`[data-video-id="${data.videoId}"]`)].forEach($video => {
+ if (!$video.dataset['data']) return
+ const videoData = JSON.parse($video.dataset['data'])
+ videoData.ignored = data.ignored
+ $video.dataset['data'] = JSON.stringify(videoData)
+ })
+ return
+ }
console.warn('unhandled', data)
} catch (err) {
console.error('sse parse error', err)
diff --git a/lib/server.js b/lib/server.js
index ff86c6e..055500c 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -164,8 +164,10 @@ export function createServer ({repo, connections = []}) {
async function ignoreVideoHandler(req, res, repo, connections = []) {
const body = await getBody(req)
let { id } = JSON.parse(body)
+ const ignored = repo.toggleIgnoreVideo(id)
+ broadcastSSE(JSON.stringify({type: 'ignored', videoId: id, ignored}), connections)
res.writeHead(200, { 'Content-Type': 'application/json' })
- return res.end(JSON.stringify(repo.toggleIgnoreVideo(id)))
+ return res.end(JSON.stringify(ignored))
}
async function deleteVideoHandler(req, res, repo, connections = []) {