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

@ -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