From 2e64c4f003d76925355da39cf3704456dc6c962e Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 15 Jun 2023 17:32:32 +0200 Subject: [PATCH 1/7] Refactor playlist logic into dedicated functions --- src/components/PlaylistAddModal.vue | 24 +++----- src/components/PlaylistsPage.vue | 86 +++++----------------------- src/components/VideoItem.vue | 7 ++- src/components/WatchVideo.vue | 7 ++- src/main.js | 87 +++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 92 deletions(-) diff --git a/src/components/PlaylistAddModal.vue b/src/components/PlaylistAddModal.vue index 3e3a4aac..77df9ac1 100644 --- a/src/components/PlaylistAddModal.vue +++ b/src/components/PlaylistAddModal.vue @@ -23,8 +23,12 @@ export default { ModalComponent, }, props: { + videoInfo: { + type: Object, + required: true, + }, videoId: { - type: String, + type: Object, required: true, }, }, @@ -62,28 +66,14 @@ export default { this.$refs.addButton.disabled = true; this.processing = true; - this.fetchJson(this.authApiUrl() + "/user/playlists/add", null, { - method: "POST", - body: JSON.stringify({ - playlistId: playlistId, - videoId: this.videoId, - }), - headers: { - Authorization: this.getAuthToken(), - "Content-Type": "application/json", - }, - }).then(json => { + this.addVideosToPlaylist(playlistId, [this.videoId], [this.videoInfo]).then(json => { this.setPreference("selectedPlaylist" + this.hashCode(this.authApiUrl()), playlistId); this.$emit("close"); if (json.error) alert(json.error); }); }, async fetchPlaylists() { - this.fetchJson(this.authApiUrl() + "/user/playlists", null, { - headers: { - Authorization: this.getAuthToken(), - }, - }).then(json => { + this.getPlaylists().then(json => { this.playlists = json; }); }, diff --git a/src/components/PlaylistsPage.vue b/src/components/PlaylistsPage.vue index 0dda0efe..58c14543 100644 --- a/src/components/PlaylistsPage.vue +++ b/src/components/PlaylistsPage.vue @@ -1,7 +1,7 @@