From d84580cf4f56a19f3beea7e693eba7b4666e3dbf Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 6 Jan 2023 19:30:28 +0100 Subject: [PATCH 1/5] Add support for playlist bookmarks --- src/App.vue | 29 +++++++++++++++---------- src/components/PlaylistPage.vue | 20 ++++++++++++++++++ src/components/PlaylistsPage.vue | 36 +++++++++++++++++++++++++++++++- src/locales/en.json | 3 ++- src/main.js | 2 ++ 5 files changed, 77 insertions(+), 13 deletions(-) diff --git a/src/App.vue b/src/App.vue index 3b1dc465..dd0f8faf 100644 --- a/src/App.vue +++ b/src/App.vue @@ -40,12 +40,13 @@ export default { darkModePreference.addEventListener("change", () => { this.setTheme(); }); - if (this.getPreferenceBoolean("watchHistory", false)) - if ("indexedDB" in window) { - const request = indexedDB.open("piped-db", 2); - request.onupgradeneeded = ev => { - const db = request.result; - console.log("Upgrading object store."); + + if ("indexedDB" in window) { + const request = indexedDB.open("piped-db", 3); + request.onupgradeneeded = ev => { + const db = request.result; + console.log("Upgrading object store."); + if (this.getPreferenceBoolean("watchHistory", false)) { if (!db.objectStoreNames.contains("watch_history")) { const store = db.createObjectStore("watch_history", { keyPath: "videoId" }); store.createIndex("video_id_idx", "videoId", { unique: true }); @@ -55,11 +56,17 @@ export default { const store = request.transaction.objectStore("watch_history"); store.createIndex("watchedAt", "watchedAt", { unique: false }); } - }; - request.onsuccess = e => { - window.db = e.target.result; - }; - } else console.log("This browser doesn't support IndexedDB"); + } + if (!db.objectStoreNames.contains("playlist_bookmarks")) { + const store = db.createObjectStore("playlist_bookmarks", { keyPath: "playlistId" }); + store.createIndex("playlist_id_idx", "playlistId", { unique: true }); + store.createIndex("id_idx", "id", { unique: true, autoIncrement: true }); + } + }; + request.onsuccess = e => { + window.db = e.target.result; + }; + } else console.log("This browser doesn't support IndexedDB"); const App = this; diff --git a/src/components/PlaylistPage.vue b/src/components/PlaylistPage.vue index d84dea9c..69234876 100644 --- a/src/components/PlaylistPage.vue +++ b/src/components/PlaylistPage.vue @@ -14,6 +14,9 @@

+ @@ -144,6 +147,23 @@ export default { }); this.download(data, this.playlist.name + ".txt", "text/plain"); }, + async bookmarkPlaylist() { + if (!this.playlist) return; + if (window.db) { + const playlistId = this.$route.query.list; + var tx = window.db.transaction("playlist_bookmarks", "readwrite"); + var store = tx.objectStore("playlist_bookmarks"); + store.put({ + playlistId: playlistId, + name: this.playlist.name, + uploader: this.playlist.uploader, + uploaderUrl: this.playlist.uploaderUrl, + thumbnail: this.playlist.thumbnailUrl, + uploaderAvatar: this.playlist.uploaderAvatar, + videos: this.playlist.videos, + }); + } + }, }, }; diff --git a/src/components/PlaylistsPage.vue b/src/components/PlaylistsPage.vue index 7383fd79..27e4834a 100644 --- a/src/components/PlaylistsPage.vue +++ b/src/components/PlaylistsPage.vue @@ -39,6 +39,25 @@

+ +
+ + thumbnail +
+ +
+
+ +
+
+
+
diff --git a/src/locales/en.json b/src/locales/en.json index 318f1bcf..32fb7197 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -120,7 +120,8 @@ "instance_donations": "Instance donations", "reply_count": "{count} replies", "no_valid_playlists": "The file doesn't contain valid playlists!", - "with_playlist": "Share with playlist" + "with_playlist": "Share with playlist", + "bookmark_playlist": "Bookmark" }, "comment": { "pinned_by": "Pinned by {author}", diff --git a/src/main.js b/src/main.js index fb15e695..c56e4ae8 100644 --- a/src/main.js +++ b/src/main.js @@ -20,6 +20,7 @@ import { faBook, faServer, faDonate, + faBookmark, } from "@fortawesome/free-solid-svg-icons"; import { faGithub, faBitcoin, faYoutube } from "@fortawesome/free-brands-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; @@ -46,6 +47,7 @@ library.add( faBook, faServer, faDonate, + faBookmark, ); import router from "@/router/router.js"; From 8e3d3d5061b30d7cf9af849f3596c32a13c34ac1 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 6 Jan 2023 20:38:42 +0100 Subject: [PATCH 2/5] Add possiblity to delete bookmark --- src/components/NavBar.vue | 4 ++-- src/components/PlaylistsPage.vue | 30 ++++++++++++++++++++++-------- src/locales/en.json | 3 ++- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/components/NavBar.vue b/src/components/NavBar.vue index 333198bd..c804ec58 100644 --- a/src/components/NavBar.vue +++ b/src/components/NavBar.vue @@ -50,7 +50,7 @@
  • -
  • +
  • @@ -79,7 +79,7 @@
  • -
  • +
  • diff --git a/src/components/PlaylistsPage.vue b/src/components/PlaylistsPage.vue index 27e4834a..33928f11 100644 --- a/src/components/PlaylistsPage.vue +++ b/src/components/PlaylistsPage.vue @@ -1,9 +1,7 @@