added love, dislike, and unlove to context menus for media items, fixed error where disabled contextmenu items would stop the rest after from adding

This commit is contained in:
booploops 2022-01-05 03:08:59 -08:00
parent 8ecd174a11
commit 091dc32fbd
5 changed files with 239 additions and 8 deletions

View file

@ -41,12 +41,14 @@ var CiderContextMenu = {
menudata.items = Object.values(menudata.items); menudata.items = Object.values(menudata.items);
} }
console.log(menudata);
// for each item in menudata create a menu item // for each item in menudata create a menu item
for (var i = 0; i < menudata.items.length; i++) { for (var i = 0; i < menudata.items.length; i++) {
let item = document.createElement("button") let item = document.createElement("button")
if (menudata.items[i]["disabled"]) { if (menudata.items[i]["disabled"] === true) {
break continue
} }
item.tabIndex = 0 item.tabIndex = 0
item.classList.add("context-menu-item") item.classList.add("context-menu-item")
@ -2587,6 +2589,59 @@ const app = new Vue({
}) })
}) })
}, },
async getRating(item) {
let type = item.type.slice(-1) === "s" ? item.type : item.type + "s"
let response = await this.mk.api.v3.music(`/v1/me/ratings/${type}?platform=web&ids=${item.id}`)
if(response.data.data.length != 0) {
let value = response.data.data[0].attributes.value
return value
}else{
return 0
}
},
love(item) {
let type = item.type.slice(-1) === "s" ? item.type : item.type + "s"
this.mk.api.v3.music(`/v1/me/ratings/${type}/${item.id}`, {}, {
fetchOptions:
{
method: "PUT",
body: JSON.stringify(
{
"type": "rating",
"attributes": {
"value": 1
}
}
)
}
})
},
dislike(item) {
let type = item.type.slice(-1) === "s" ? item.type : item.type + "s"
this.mk.api.v3.music(`/v1/me/ratings/${type}/${item.id}`, {}, {
fetchOptions:
{
method: "PUT",
body: JSON.stringify(
{
"type": "rating",
"attributes": {
"value": -1
}
}
)
}
})
},
unlove(item) {
let type = item.type.slice(-1) === "s" ? item.type : item.type + "s"
this.mk.api.v3.music(`/v1/me/ratings/${type}/${item.id}`, {}, {
fetchOptions:
{
method: "DELETE",
}
})
},
volumeWheel(event) { volumeWheel(event) {
if (event.deltaY < 0) { if (event.deltaY < 0) {
if(this.mk.volume < 1){ if(this.mk.volume < 1){
@ -2682,6 +2737,38 @@ const app = new Vue({
// if (!isLibrary) {app.addToLibrary(item_id); this.mk.nowPlayingItem.attributes.playParams["isLibrary"] = true} else { app.removeFromLibrary(data_type,item_id); this.mk.nowPlayingItem.attributes.playParams["isLibrary"] = false}; // if (!isLibrary) {app.addToLibrary(item_id); this.mk.nowPlayingItem.attributes.playParams["isLibrary"] = true} else { app.removeFromLibrary(data_type,item_id); this.mk.nowPlayingItem.attributes.playParams["isLibrary"] = false};
} }
}, },
{
"id": "love",
"name": "Love",
"disabled": true,
"action": function () {
app.love(app.mk.nowPlayingItem)
}
},
{
"id": "unlove",
"name": "Unlove",
"disabled": true,
"action": function () {
app.unlove(app.mk.nowPlayingItem)
}
},
{
"id": "dislike",
"name": "Dislike",
"disabled": true,
"action": function () {
app.dislike(app.mk.nowPlayingItem)
}
},
{
"id": "undo_dislike",
"name": "Undo dislike",
"disabled": true,
"action": function () {
app.unlove(app.mk.nowPlayingItem)
}
},
{ {
"name": "Start Radio", "name": "Start Radio",
"action": function () { "action": function () {
@ -2700,6 +2787,15 @@ const app = new Vue({
menus.normal.items = menus.normal.items.concat(this.contextExt.normal) menus.normal.items = menus.normal.items.concat(this.contextExt.normal)
} }
} }
let rating = await app.getRating(app.mk.nowPlayingItem)
if(rating == 0) {
menus.normal.items.find(x => x.id == 'love').disabled = false
menus.normal.items.find(x => x.id == 'dislike').disabled = false
}else if(rating == 1) {
menus.normal.items.find(x => x.id == 'unlove').disabled = false
}else if(rating == -1) {
menus.normal.items.find(x => x.id == 'undo_dislike').disabled = false
}
CiderContextMenu.Create(event, menus[useMenu]) CiderContextMenu.Create(event, menus[useMenu])
}, },
LastFMDeauthorize() { LastFMDeauthorize() {

View file

@ -583,17 +583,21 @@ input[type=range].web-slider::-webkit-slider-runnable-track {
text-align: left; text-align: left;
color: #eee; color: #eee;
font-family: inherit; font-family: inherit;
font-size: 15px; font-size: 14px;
padding: 8px 12px; padding: 6px 12px;
border: 0px; border: 0px;
appearance: none; appearance: none;
border-radius: 6px; border-radius: 6px;
margin: 2px 0px; margin: 2px 0px;
&:hover { &:hover {
background: var(--keyColor); background: var(--selected);
cursor: pointer; cursor: pointer;
} }
&:active {
background: var(--selected-click);
}
} }
.context-menu-body { .context-menu-body {

View file

@ -87,7 +87,7 @@
}, },
mounted() { mounted() {
let duration = this.item.attributes.durationInMillis ?? 0 let duration = this.item.attributes.durationInMillis ?? 0
if(duration == 0 || !this.showDuration) { if (duration == 0 || !this.showDuration) {
this.displayDuration = false this.displayDuration = false
} }
}, },
@ -179,7 +179,7 @@
} }
} }
}, },
contextMenu(event) { async contextMenu(event) {
let self = this let self = this
let data_type = this.getDataType() let data_type = this.getDataType()
let item_id = this.item.attributes.playParams.id ?? this.item.id let item_id = this.item.attributes.playParams.id ?? this.item.id
@ -277,6 +277,38 @@
app.selectedMediaItems = [] app.selectedMediaItems = []
} }
}, },
{
"id": "love",
"name": "Love",
"disabled": true,
"action": function () {
app.love(self.item)
}
},
{
"id": "unlove",
"name": "Unlove",
"disabled": true,
"action": function () {
app.unlove(self.item)
}
},
{
"id": "dislike",
"name": "Dislike",
"disabled": true,
"action": function () {
app.dislike(self.item)
}
},
{
"id": "undo_dislike",
"name": "Undo dislike",
"disabled": true,
"action": function () {
app.unlove(self.item)
}
},
{ {
"name": "Go to Artist", "name": "Go to Artist",
"action": function () { "action": function () {
@ -307,6 +339,16 @@
menus.multiple.items = menus.multiple.items.concat(this.contextExt.multiple) menus.multiple.items = menus.multiple.items.concat(this.contextExt.multiple)
} }
} }
let rating = await app.getRating(self.item)
if(rating == 0) {
menus.normal.items.find(x => x.id == 'love').disabled = false
menus.normal.items.find(x => x.id == 'dislike').disabled = false
}else if(rating == 1) {
menus.normal.items.find(x => x.id == 'unlove').disabled = false
}else if(rating == -1) {
menus.normal.items.find(x => x.id == 'undo_dislike').disabled = false
}
CiderContextMenu.Create(event, menus[useMenu]) CiderContextMenu.Create(event, menus[useMenu])
}, },
visibilityChanged: function (isVisible, entry) { visibilityChanged: function (isVisible, entry) {

View file

@ -214,11 +214,44 @@
} }
}, },
{ {
"id": "addToPlaylist",
"name": "Add to Playlist...", "name": "Add to Playlist...",
"action": function () { "action": function () {
app.promptAddToPlaylist() app.promptAddToPlaylist()
} }
}, },
{
"id": "love",
"name": "Love",
"disabled": true,
"action": function () {
app.love(self.item)
}
},
{
"id": "unlove",
"name": "Unlove",
"disabled": true,
"action": function () {
app.unlove(self.item)
}
},
{
"id": "dislike",
"name": "Dislike",
"disabled": true,
"action": function () {
app.dislike(self.item)
}
},
{
"id": "undo_dislike",
"name": "Undo dislike",
"disabled": true,
"action": function () {
app.unlove(self.item)
}
},
{ {
"name": (this.addedToLibrary) ? "Remove from Library..." : "Add to Library...", "name": (this.addedToLibrary) ? "Remove from Library..." : "Add to Library...",
"action": async function () { "action": async function () {
@ -232,7 +265,21 @@
] ]
} }
} }
if ((self.item.attributes.playParams.kind ?? self.item.type).includes("playlist")) { menus.normal.items.splice(2, 1);} let rating = await app.getRating(self.item)
if(rating == 0) {
menus.normal.items.find(x => x.id == 'love').disabled = false
menus.normal.items.find(x => x.id == 'dislike').disabled = false
}else if(rating == 1) {
menus.normal.items.find(x => x.id == 'unlove').disabled = false
}else if(rating == -1) {
menus.normal.items.find(x => x.id == 'undo_dislike').disabled = false
}
if ((self.item.attributes.playParams.kind ?? self.item.type).includes("playlist")) {
// remove the add to playlist option by id "addToPlaylist" using the .filter() method
menus.normal.items = menus.normal.items.filter(function (item) {
return item.id != "addToPlaylist"
})
}
CiderContextMenu.Create(event, menus[useMenu]) CiderContextMenu.Create(event, menus[useMenu])
}, },
} }

View file

@ -263,6 +263,38 @@
; ;
} }
}, },
{
"id": "love",
"name": "Love",
"disabled": true,
"action": function () {
app.love(self.item)
}
},
{
"id": "unlove",
"name": "Unlove",
"disabled": true,
"action": function () {
app.unlove(self.item)
}
},
{
"id": "dislike",
"name": "Dislike",
"disabled": true,
"action": function () {
app.dislike(self.item)
}
},
{
"id": "undo_dislike",
"name": "Undo dislike",
"disabled": true,
"action": function () {
app.unlove(self.item)
}
},
{ {
"name": "Share", "name": "Share",
"action": function () { "action": function () {
@ -278,6 +310,16 @@
return item.id != "addToPlaylist" return item.id != "addToPlaylist"
}) })
} }
let rating = await app.getRating(self.item)
if(rating == 0) {
menus.normal.items.find(x => x.id == 'love').disabled = false
menus.normal.items.find(x => x.id == 'dislike').disabled = false
}else if(rating == 1) {
menus.normal.items.find(x => x.id == 'unlove').disabled = false
}else if(rating == -1) {
menus.normal.items.find(x => x.id == 'undo_dislike').disabled = false
}
if (this.contextExt) { if (this.contextExt) {
if (this.contextExt.normal) { if (this.contextExt.normal) {
menus.normal.items = menus.normal.items.concat(this.contextExt.normal) menus.normal.items = menus.normal.items.concat(this.contextExt.normal)