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:
parent
8ecd174a11
commit
091dc32fbd
5 changed files with 239 additions and 8 deletions
|
@ -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() {
|
||||
|
|
|
@ -583,17 +583,21 @@ input[type=range].web-slider::-webkit-slider-runnable-track {
|
|||
text-align: left;
|
||||
color: #eee;
|
||||
font-family: inherit;
|
||||
font-size: 15px;
|
||||
padding: 8px 12px;
|
||||
font-size: 14px;
|
||||
padding: 6px 12px;
|
||||
border: 0px;
|
||||
appearance: none;
|
||||
border-radius: 6px;
|
||||
margin: 2px 0px;
|
||||
|
||||
&:hover {
|
||||
background: var(--keyColor);
|
||||
background: var(--selected);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: var(--selected-click);
|
||||
}
|
||||
}
|
||||
|
||||
.context-menu-body {
|
||||
|
|
|
@ -179,7 +179,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
contextMenu(event) {
|
||||
async contextMenu(event) {
|
||||
let self = this
|
||||
let data_type = this.getDataType()
|
||||
let item_id = this.item.attributes.playParams.id ?? this.item.id
|
||||
|
@ -277,6 +277,38 @@
|
|||
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",
|
||||
"action": function () {
|
||||
|
@ -307,6 +339,16 @@
|
|||
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])
|
||||
},
|
||||
visibilityChanged: function (isVisible, entry) {
|
||||
|
|
|
@ -214,11 +214,44 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"id": "addToPlaylist",
|
||||
"name": "Add to Playlist...",
|
||||
"action": function () {
|
||||
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...",
|
||||
"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])
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
"action": function () {
|
||||
|
@ -278,6 +310,16 @@
|
|||
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.normal) {
|
||||
menus.normal.items = menus.normal.items.concat(this.contextExt.normal)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue