From 17e24d4e4f0bc4089f2e754ef3dcd44fec739268 Mon Sep 17 00:00:00 2001 From: booploops <49113086+booploops@users.noreply.github.com> Date: Wed, 22 Dec 2021 15:54:01 -0800 Subject: [PATCH] playlist utils added --- src/renderer/index.js | 32 ++++++++++++++++++--- src/renderer/views/components/playlists.ejs | 0 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/renderer/views/components/playlists.ejs diff --git a/src/renderer/index.js b/src/renderer/index.js index a03eaa07..74577319 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -396,9 +396,7 @@ const app = new Vue({ ipcRenderer.invoke('setStoreValue', 'volume', this.mk.volume) }) - this.apiCall('https://api.music.apple.com/v1/me/library/playlist-folders/p.playlistsroot/children/', res => { - self.playlists.listing = res.data - }) + this.refreshPlaylists() document.body.removeAttribute("loading") if (window.location.hash != "") { this.appRoute(window.location.hash) @@ -449,6 +447,32 @@ const app = new Vue({ }) } }, + async refreshPlaylists() { + let self = this + this.apiCall('https://api.music.apple.com/v1/me/library/playlist-folders/p.playlistsroot/children/', res => { + self.playlists.listing = res.data + }) + }, + async editPlaylist(id, name = "New Playlist") { + await app.mk.api.library.editPlaylist(id, {name: name}).then(res => { + self.refreshPlaylists() + }) + }, + async newPlaylist(name = "New Playlist", tracks = []) { + let self = this + await app.mk.api.library.createPlaylist({name: name, tracks: tracks}).then(res => { + self.refreshPlaylists() + appRoute(`playlist_` + res.id); + }) + }, + async deletePlaylist(id) { + let self = this + if(confirm(`Are you sure you want to delete "${this.playlists.listing[id].attributes.name}"?`)) { + await app.mk.api.library.deletePlaylist(id).then(res=>{ + self.refreshPlaylists() + }) + } + }, async showCollection(response, title, type) { let self = this this.collectionList.response = response @@ -1928,7 +1952,7 @@ const app = new Vue({ }) }) }, - apiCall(url, callback) { + async apiCall(url, callback) { const xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange = (e) => { diff --git a/src/renderer/views/components/playlists.ejs b/src/renderer/views/components/playlists.ejs new file mode 100644 index 00000000..e69de29b