From f769d6070e1d821d677b308adf9e238af20e4280 Mon Sep 17 00:00:00 2001 From: Robbe Van Petegem Date: Sat, 20 Apr 2024 12:01:34 +0200 Subject: [PATCH] Use endpoint for playlist items when adding a new item (#1115) * Use endpoint for playlist items when adding a new item * Run `yarn lint` * Update to match api * Use latest api-client-js --------- Co-authored-by: Charlotte Van Petegem --- package.json | 2 +- src/components/AddToPlaylist.vue | 14 ++++++++++---- src/store/playlists.js | 11 +++++++++++ yarn.lock | 10 +++++----- yarn.nix | 8 ++++---- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index a6c08269..ddebdc4d 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "i18n:report": "vue-cli-service i18n:report --src './src/**/*.?(js|vue)' --locales './src/locales/**/*.json'" }, "dependencies": { - "@accentor/api-client-js": "^0.19.1", + "@accentor/api-client-js": "^0.20.0", "@mdi/font": "^7.4.47", "@mdi/svg": "^7.4.47", "fetch-retry": "^6.0.0", diff --git a/src/components/AddToPlaylist.vue b/src/components/AddToPlaylist.vue index 79f1fe26..147724f6 100644 --- a/src/components/AddToPlaylist.vue +++ b/src/components/AddToPlaylist.vue @@ -98,7 +98,7 @@ export default { }, }, methods: { - ...mapActions("playlists", ["update"]), + ...mapActions("playlists", ["addItem"]), filterName(item, queryText) { const search = queryText.toLowerCase(); return item.name.toLowerCase().indexOf(search) > -1; @@ -108,10 +108,16 @@ export default { return; } - const newItems = [...this.selectedPlaylist.item_ids, this.item.id]; - this.update({ + // Item type requires a capitalized string + const item_type = + this.selectedPlaylist.playlist_type.charAt(0).toUpperCase() + + this.selectedPlaylist.playlist_type.slice(1); + this.addItem({ id: this.selectedPlaylist.id, - newPlaylist: { item_ids: newItems }, + newItem: { + item_id: this.item.id, + item_type, + }, }).finally(() => { this.dialog = false; }); diff --git a/src/store/playlists.js b/src/store/playlists.js index 0d30e1f7..18095b91 100644 --- a/src/store/playlists.js +++ b/src/store/playlists.js @@ -92,6 +92,17 @@ export default { return false; } }, + async addItem({ commit, rootState, dispatch }, { id, newItem }) { + try { + await api.playlists.addItem(rootState.auth, id, { + playlist_item: newItem, + }); + await dispatch("read", newItem.playlist_id); + } catch (error) { + commit("addError", error, { root: true }); + return false; + } + }, async destroy({ commit, rootState }, id) { try { await api.playlists.destroy(rootState.auth, id); diff --git a/yarn.lock b/yarn.lock index 2d4d7200..792573a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7,12 +7,12 @@ resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf" integrity sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA== -"@accentor/api-client-js@^0.19.1": - version "0.19.1" - resolved "https://registry.yarnpkg.com/@accentor/api-client-js/-/api-client-js-0.19.1.tgz#cb1867fbf06cb29e5f4533ca5ff596e4a5a69001" - integrity sha512-DriWKP3Mw4fPvMtBMEn41TWlQzHsSJGtvnmkNbP/1Rh9XwzNTkRjIct7UyM2FlOcad9MbEWGob3Ce/2n+jHfRw== +"@accentor/api-client-js@^0.20.0": + version "0.20.0" + resolved "https://registry.yarnpkg.com/@accentor/api-client-js/-/api-client-js-0.20.0.tgz#df89da9cb387b3c313514659a633a6d0aea075e8" + integrity sha512-sZU4QUid6Di1OPsllB22QyorMGV/fasbVVNd1mBy3tIshXQEVlSzanf489tl3AgAm3Nbatb51a30FKKZuGRvEg== dependencies: - fetch-retry "^5.0.6" + fetch-retry "^6.0.0" "@achrinza/node-ipc@^9.2.5": version "9.2.8" diff --git a/yarn.nix b/yarn.nix index 21be8b7e..ced93756 100644 --- a/yarn.nix +++ b/yarn.nix @@ -10,11 +10,11 @@ }; } { - name = "_accentor_api_client_js___api_client_js_0.19.1.tgz"; + name = "_accentor_api_client_js___api_client_js_0.20.0.tgz"; path = fetchurl { - name = "_accentor_api_client_js___api_client_js_0.19.1.tgz"; - url = "https://registry.yarnpkg.com/@accentor/api-client-js/-/api-client-js-0.19.1.tgz"; - sha512 = "DriWKP3Mw4fPvMtBMEn41TWlQzHsSJGtvnmkNbP/1Rh9XwzNTkRjIct7UyM2FlOcad9MbEWGob3Ce/2n+jHfRw=="; + name = "_accentor_api_client_js___api_client_js_0.20.0.tgz"; + url = "https://registry.yarnpkg.com/@accentor/api-client-js/-/api-client-js-0.20.0.tgz"; + sha512 = "sZU4QUid6Di1OPsllB22QyorMGV/fasbVVNd1mBy3tIshXQEVlSzanf489tl3AgAm3Nbatb51a30FKKZuGRvEg=="; }; } {