improvements to add to library on list item

This commit is contained in:
booploops 2022-01-13 04:54:11 -08:00
parent 50aa8cb253
commit 3d4f0afe8b
2 changed files with 53 additions and 4 deletions

View file

@ -2571,7 +2571,7 @@ const app = new Vue({
if (type.slice(-1) != "s") { if (type.slice(-1) != "s") {
type += "s" type += "s"
} }
let id = item.playParams.catalogId ? item.playParams.catalogId : item.id let id = item.attributes.playParams.catalogId ?? item.id
let index = types.findIndex(function (type) { let index = types.findIndex(function (type) {
return type.type == this return type.type == this

View file

@ -9,13 +9,17 @@
:data-islibrary="this.item.attributes.playParams.isLibrary ?? false" :data-islibrary="this.item.attributes.playParams.isLibrary ?? false"
:key="item.attributes.playParams.id ?? item.id" :key="item.attributes.playParams.id ?? item.id"
class="cd-mediaitem-list-item" class="cd-mediaitem-list-item"
@mouseenter="checkLibrary"
@mouseover="showInLibrary = true"
@mouseleave="showInLibrary = false"
:class="[{'mediaitem-selected': app.select_hasMediaItem(guid)}, addClasses]"> :class="[{'mediaitem-selected': app.select_hasMediaItem(guid)}, addClasses]">
<template v-if="isVisible"> <template v-if="isVisible">
<div class="isLibrary" v-if="showLibraryStatus == true"> <div class="isLibrary" :style="{opacity: (showInLibrary ? 1 : 0)}" v-if="showLibraryStatus == true">
<button @click="addToLibrary()" <button @click="addToLibrary()"
v-if="!app.isInLibrary(item.attributes.playParams) && !addedToLibrary">🖤 v-if="!addedToLibrary">
<div class="svg-icon" :style="{'--color': 'var(--keyColor)', '--url': 'url(./assets/feather/plus.svg)'}"></div>
</button> </button>
<button v-else @click="removeFromLibrary()">❤️</button> <button v-else style="opacity:0;">❤️</button>
</div> </div>
<div class="artwork" v-if="showArtwork == true"> <div class="artwork" v-if="showArtwork == true">
<mediaitem-artwork <mediaitem-artwork
@ -67,6 +71,7 @@
template: '#mediaitem-list-item', template: '#mediaitem-list-item',
data: function () { data: function () {
return { return {
showInLibrary: false,
isVisible: false, isVisible: false,
addedToLibrary: false, addedToLibrary: false,
guid: this.uuidv4(), guid: this.uuidv4(),
@ -94,6 +99,17 @@
this.getClasses() this.getClasses()
}, },
methods: { methods: {
async checkLibrary() {
if(this.addedToLibrary) {return this.addedToLibrary}
if(this.item.type.includes("library-") || this.item.type.includes("station")) {
this.addedToLibrary = true
return
}
this.$root.inLibrary([this.item]).then(res => {
this.addedToLibrary = res[0].attributes.inLibrary
})
return this.addedToLibrary
},
getClasses() { getClasses() {
if(this.classList) { if(this.classList) {
this.addClasses = {} this.addClasses = {}
@ -299,6 +315,25 @@
}, },
], ],
items: [ items: [
{
"id": "addToLibrary",
"icon": "./assets/feather/plus.svg",
"name": "Add to library",
"hidden": false,
"disabled": true,
"action": function () {
self.addToLibrary()
}
},
{
"id": "removeFromLibrary",
"icon": "./assets/feather/x-circle.svg",
"name": "Remove from library",
"hidden": true,
"action": function () {
self.removeFromLibrary()
}
},
{ {
"icon": "./assets/feather/list.svg", "icon": "./assets/feather/list.svg",
"name": "Add to Playlist...", "name": "Add to Playlist...",
@ -372,6 +407,20 @@
} }
app.showMenuPanel(menus[useMenu], event) app.showMenuPanel(menus[useMenu], event)
try {
await this.checkLibrary().then(res => {
console.log(res)
if(res) {
menus.normal.items.find(x => x.id == 'addToLibrary').hidden = true
menus.normal.items.find(x => x.id == 'removeFromLibrary').hidden = false
}else{
menus.normal.items.find(x => x.id == 'addToLibrary').disabled = false
}
})
}catch(e) {
}
try{ try{
let rating = await app.getRating(self.item) let rating = await app.getRating(self.item)
if (rating == 0) { if (rating == 0) {