some fixes to the heart button

This commit is contained in:
vapormusic 2021-12-25 10:47:25 +07:00
parent 25221521cd
commit 3c92dc5e83
3 changed files with 41 additions and 7 deletions

View file

@ -1448,6 +1448,12 @@ const app = new Vue({
self.getLibrarySongsFull(true)
})
},
removeFromLibrary(kind,id) {
let self = this
this.mk.api.library.remove({[kind]: id }).then((data) => {
self.getLibrarySongsFull(true)
})
},
async loadYTLyrics() {
const track = (this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem.title ?? '' : '';
const artist = (this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem.artistName ?? '' : '';

View file

@ -15,7 +15,7 @@
<button @click="addToLibrary()"
v-if="!app.isInLibrary(item.attributes.playParams) && !addedToLibrary">🖤
</button>
<button v-else>❤️</button>
<button v-else @click="removeFromLibrary()" >❤️</button>
</div>
<div class="artwork" v-if="showArtwork == true">
<mediaitem-artwork
@ -295,6 +295,26 @@
this.addedToLibrary = true
}
},
async removeFromLibrary() {
let item = this.item
let params = {"fields[songs]": "inLibrary","fields[albums]": "inLibrary","relate" : "library"}
let id = item.id ?? item.attributes.playParams.id
let res = await app.mkapi(item.attributes.playParams.kind ?? item.type, item.attributes.playParams.isLibrary ?? false , item.attributes.playParams.id ?? item.id, params);
if (res && res.relationships && res.relationships.library && res.relationships.library.data && res.relationships.library.data.length > 0) {
id = res.relationships.library.data[0].id
}
let kind = this.item.attributes.playParams.kind ?? this.data.item ?? '';
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
if (item.attributes.playParams.id) {
console.log('remove from library', id)
app.removeFromLibrary(truekind, id)
this.addedToLibrary = false
} else if (item.id) {
console.log('remove from library', id)
app.removeFromLibrary(truekind, id)
this.addedToLibrary = false
}
},
playTrack() {
let item = this.item
let parent = this.parent

View file

@ -109,11 +109,13 @@
},
methods: {
async isInLibrary () {
if (this.data.type && !this.data.type.includes('library')){
if (this.data.type && !this.data.type.includes("library")){
// please keep using vars here
var params = {"fields[albums]": "inLibrary","relate" : "library"}
var res = await app.mkapi(this.data.attributes.playParams.kind ?? this.data.type, false , this.data.attributes.playParams.id ?? this.data.id, params);
this.inLibrary = (res && res.attributes && res.attributes.inLibrary) ? res.attributes.inLibrary : false} else {this.inLibrary = true}
var params = {"fields[playlists]": "inLibrary","fields[albums]": "inLibrary","relate" : "library"}
var res = await app.mkapi(this.data.attributes.playParams.kind ?? this.data.type, this.data.attributes.playParams.isLibrary ?? false , this.data.attributes.playParams.id ?? this.data.id, params);
this.inLibrary = (res && res.attributes && res.attributes.inLibrary) ? res.attributes.inLibrary : false
console.log(res)
} else {this.inLibrary = true}
},
editPlaylist() {
app.editPlaylist(this.data.id, this.data.attributes.name);
@ -123,10 +125,16 @@
app.mk.addToLibrary(id)
this.inLibrary = true
},
removeFromLibrary(id) {
async removeFromLibrary(id) {
var params = {"fields[somgs]": "inLibrary","fields[albums]": "inLibrary","relate" : "library"}
var id = this.data.id ?? this.data.attributes.playParams.id
var res = await app.mkapi(this.data.attributes.playParams.kind ?? this.data.type, this.data.attributes.playParams.isLibrary ?? false , this.data.attributes.playParams.id ?? this.data.id, params);
if (res && res.relationships && res.relationships.library && res.relationships.library.data && res.relationships.library.data.length > 0) {
id = res.relationships.library.data[0].id
}
let kind = this.data.attributes.playParams.kind ?? this.data.type ?? '';
var truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
app.mk.api.library.remove({[truekind]: this.data.id ?? this.data.attributes.playParams.id })
app.mk.api.library.remove({[truekind]: id })
this.inLibrary = false
},
editPlaylistName() {