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: explicit ignore/unignore action, rm toggle ignore

Christian Feid03a35d81e29
diff --git a/client/components/video-element.js b/client/components/video-element.js
index a95ec8b..3820864 100644
--- a/client/components/video-element.js
+++ b/client/components/video-element.js
@@ -213,7 +213,7 @@ class VideoElement extends HTMLElement {
fetch('/api/ignore-video', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ id: this.video.id })
+ body: JSON.stringify({ id: this.video.id, ignore: !this.video.ignored })
})
.then(() => {
this.remove()
diff --git a/lib/repository.js b/lib/repository.js
index 10cbece..276fc2a 100644
--- a/lib/repository.js
+++ b/lib/repository.js
@@ -185,18 +185,14 @@ export default class Repository {
fs.writeFileSync(this.paths.videos, JSON.stringify(this.videos, null, 2))
}
- toggleIgnoreVideo (id) {
- const index = this.videos.findIndex(v => v.id === id)
- let ignored = false
- if (index !== -1) {
- this.videos[index].ignored = !this.videos[index].ignored
- ignored = this.videos[index].ignored
- console.log('toggled ignore video', ignored, this.videos[index].id)
- } else {
- console.log('cannot set video ignored, video does not exist', id)
- }
- this.saveVideos()
- return ignored
+ ignoreVideo (id) {
+ this.updateVideo(id, { ignored: true })
+ return true
+ }
+
+ unignoreVideo (id) {
+ this.updateVideo(id, { ignored: false })
+ return false
}
setVideoTranscript (id, transcript = '') {
diff --git a/server/router/api.js b/server/router/api.js
index d7291c5..129a783 100644
--- a/server/router/api.js
+++ b/server/router/api.js
@@ -156,8 +156,8 @@ async function summarizeVideoHandler (req, res, repo, connections = [], state =
async function ignoreVideoHandler (req, res, repo, connections = []) {
const body = await getBody(req)
- const { id } = JSON.parse(body)
- const ignored = repo.toggleIgnoreVideo(id)
+ const { id, ignore } = JSON.parse(body)
+ const ignored = ignore ? repo.ignoreVideo(id) : repo.unignoreVideo(id)
broadcastSSE(JSON.stringify({ type: 'ignored', videoId: id, ignored }), connections)
res.writeHead(200, { 'Content-Type': 'application/json' })
return res.end(JSON.stringify(ignored))
diff --git a/test/repository.test.js b/test/repository.test.js
index fffae9f..05e7812 100644
--- a/test/repository.test.js
+++ b/test/repository.test.js
@@ -74,10 +74,12 @@ describe('repository', () => {
assert.deepEqual(repo.getVideo('12345'), { id: '12345', channelName: 'tester', title: 'The Code', description: 'some description in common', downloaded: false })
})
- test('toggles ignore video', () => {
+ test('set ignored/unignored video', () => {
repo.upsertVideos([video1, video2])
- repo.toggleIgnoreVideo('12345')
+ repo.ignoreVideo('12345')
+ repo.unignoreVideo('67890')
assert.equal(repo.getVideo('12345').ignored, true)
+ assert.equal(repo.getVideo('67890').ignored, false)
})
test('marks video as downloaded', () => {