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);
}
console.log(menudata);
// for each item in menudata create a menu item
for (var i = 0; i < menudata.items.length; i++) {
let item = document.createElement("button")
if (menudata.items[i]["disabled"]) {
break
if (menudata.items[i]["disabled"] === true) {
continue
}
item.tabIndex = 0
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) {
if (event.deltaY < 0) {
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};
}
},
{
"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",
"action": function () {
@ -2700,6 +2787,15 @@ const app = new Vue({
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])
},
LastFMDeauthorize() {