follow has been migrated to favorites
This commit is contained in:
parent
05b6ea112e
commit
d7b314e0f5
9 changed files with 257 additions and 222 deletions
|
@ -193,6 +193,8 @@
|
|||
"term.confirmLogout": "Are you sure you want to logout?",
|
||||
"term.creditDesignedBy": "Designed by ${authorUsername}",
|
||||
"term.discNumber": "Disc ${discNumber}",
|
||||
"home.syncFavorites": "Sync Favorites",
|
||||
"home.syncFavorites.gettingArtists": "Getting Favorited Artists...",
|
||||
"home.title": "Home",
|
||||
"home.recentlyPlayed": "Recently Played",
|
||||
"home.recentlyAdded": "Recently Added",
|
||||
|
|
|
@ -516,7 +516,8 @@ const app = new Vue({
|
|||
window.location.hash = `#charts/top`
|
||||
} else {
|
||||
const id = url.split("id=")[1];
|
||||
window.location.hash = `#groupings/${id}`}
|
||||
window.location.hash = `#groupings/${id}`
|
||||
}
|
||||
},
|
||||
navigateForward() {
|
||||
history.forward()
|
||||
|
@ -841,7 +842,8 @@ const app = new Vue({
|
|||
user: `${user.username}#${user.discriminator}`,
|
||||
userid: user.id
|
||||
}));
|
||||
}})
|
||||
}
|
||||
})
|
||||
|
||||
ipcRenderer.on('getUpdatedLocalList', (event, data) => {
|
||||
console.log("cider-local", data);
|
||||
|
@ -1249,6 +1251,66 @@ const app = new Vue({
|
|||
}
|
||||
})
|
||||
},
|
||||
async syncFavorites() {
|
||||
const notify = notyf.open({
|
||||
className: "notyf-info",
|
||||
type: "info",
|
||||
message: `[${app.getLz('home.syncFavorites')}] ${app.getLz('home.syncFavorites.gettingArtists')}`
|
||||
})
|
||||
const results = await MusicKitTools.v3Continuous({
|
||||
href: "/v1/me/library/artists", options: {
|
||||
"include": ["catalog"],
|
||||
"fields[artists]": ["inFavorites"]
|
||||
}
|
||||
})
|
||||
let favs = []
|
||||
// for each result
|
||||
results.forEach(result => {
|
||||
try {
|
||||
if (result.relationships?.catalog?.data[0]?.attributes?.inFavorites) {
|
||||
if(!favs.includes(result.relationships?.catalog?.data[0].id)) {
|
||||
favs.push(result.relationships?.catalog?.data[0].id)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
e = null
|
||||
}
|
||||
})
|
||||
notyf.success(`[${app.getLz('home.syncFavorites')}] ${app.getLz('action.done')}`)
|
||||
app.cfg.home.followedArtists = favs
|
||||
return favs
|
||||
},
|
||||
async setArtistFavorite(id, val = true) {
|
||||
if(val) {
|
||||
if(!app.cfg.home.followedArtists.includes(id)) {
|
||||
app.cfg.home.followedArtists.push(id)
|
||||
}
|
||||
await app.mk.api.v3.music(`/v1/me/favorites`, {
|
||||
"art[url]": "f",
|
||||
"ids[artists]": app.artistPage.data.id,
|
||||
"l": app.mklang,
|
||||
"platform": "web"
|
||||
}, {
|
||||
fetchOptions: {
|
||||
method: "POST"
|
||||
}
|
||||
})
|
||||
}else{
|
||||
if(app.cfg.home.followedArtists.includes(id)) {
|
||||
app.cfg.home.followedArtists.splice(app.cfg.home.followedArtists.indexOf(id), 1)
|
||||
}
|
||||
await app.mk.api.v3.music(`/v1/me/favorites`, {
|
||||
"art[url]": "f",
|
||||
"ids[artists]": app.artistPage.data.id,
|
||||
"l": app.mklang,
|
||||
"platform": "web"
|
||||
}, {
|
||||
fetchOptions: {
|
||||
method: "DELETE"
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
async refreshPlaylists(localOnly = false, useCachedPlaylists = true) {
|
||||
let self = this
|
||||
let trackMap = this.cfg.advanced.playlistTrackMapping
|
||||
|
@ -2038,16 +2100,6 @@ const app = new Vue({
|
|||
this.getArtistFromID(id)
|
||||
//this.getTypeFromID("artist",id,isLibrary,query)
|
||||
},
|
||||
followArtistById(id, follow) {
|
||||
if (follow && !this.followingArtist(id)) {
|
||||
this.cfg.home.followedArtists.push(id)
|
||||
} else {
|
||||
let index = this.cfg.home.followedArtists.indexOf(id)
|
||||
if (index > -1) {
|
||||
this.cfg.home.followedArtists.splice(index, 1)
|
||||
}
|
||||
}
|
||||
},
|
||||
followingArtist(id) {
|
||||
console.debug(`check for ${id}`)
|
||||
return this.cfg.home.followedArtists.includes(id)
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<div class="artist-chip__name">
|
||||
<span>{{ item.attributes.name }}</span>
|
||||
</div>
|
||||
<button @click="$root.followArtistById(artist.id, true)" title="Follow" v-if="!$root.followingArtist(artist.id)" class="artist-chip__follow codicon codicon-add"></button>
|
||||
<button @click="$root.followArtistById(artist.id, false)" title="Following" v-else class="artist-chip__follow codicon codicon-check"></button>
|
||||
<button @click="$root.setArtistFavorite(artist.id, true)" title="Follow" v-if="!$root.followingArtist(artist.id)" class="artist-chip__follow codicon codicon-add"></button>
|
||||
<button @click="$root.setArtistFavorite(artist.id, false)" title="Following" v-else class="artist-chip__follow codicon codicon-check"></button>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
|
|
|
@ -534,19 +534,16 @@
|
|||
let followActions = {
|
||||
follow: {
|
||||
icon: "./assets/feather/plus-circle.svg",
|
||||
name: app.getLz('action.follow'),
|
||||
name: app.getLz('action.favorite'),
|
||||
action: () => {
|
||||
self.app.cfg.home.followedArtists.push(this.item.id)
|
||||
self.$root.setArtistFavorite(this.item.id, true)
|
||||
}
|
||||
},
|
||||
unfollow: {
|
||||
icon: "./assets/feather/x-circle.svg",
|
||||
name: app.getLz('action.unfollow'),
|
||||
name: app.getLz('action.removeFavorite'),
|
||||
action: () => {
|
||||
let index = self.app.cfg.home.followedArtists.indexOf(this.item.id)
|
||||
if (index > -1) {
|
||||
self.app.cfg.home.followedArtists.splice(index, 1)
|
||||
}
|
||||
self.$root.setArtistFavorite(this.item.id, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
<div class="col nopadding">
|
||||
<h3>{{app.getLz('home.followedArtists')}}</h3>
|
||||
</div>
|
||||
<div class="col-auto nopadding flex-center">
|
||||
<button class="cd-btn-seeall" @click="syncFavorites()" v-if="!syncingFavs">{{app.getLz('home.syncFavorites')}}</button>
|
||||
<div class="spinner" style="height: 26px;" v-else></div>
|
||||
</div>
|
||||
</div>
|
||||
<vue-horizontal>
|
||||
<div v-for="artist in artists" style="margin: 6px;">
|
||||
|
@ -14,7 +18,7 @@
|
|||
<button @click="unfollow(artist.id)" class="md-btn md-btn-glyph" style="display:flex;">
|
||||
<div class="sidebar-icon">
|
||||
<div class="svg-icon" :style="{'--url': 'url(./assets/feather/x-circle.svg)'}"></div>
|
||||
</div> {{app.getLz('action.unfollow')}}
|
||||
</div> {{app.getLz('action.removeFavorite')}}
|
||||
</button>
|
||||
</div>
|
||||
</vue-horizontal>
|
||||
|
@ -53,7 +57,8 @@
|
|||
app: this.$root,
|
||||
followedArtists: this.$root.cfg.home.followedArtists,
|
||||
artistFeed: [],
|
||||
artists: []
|
||||
artists: [],
|
||||
syncingFavs: false
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
|
@ -61,7 +66,13 @@
|
|||
await this.getArtistFeed()
|
||||
},
|
||||
methods: {
|
||||
unfollow(id) {
|
||||
async syncFavorites() {
|
||||
this.syncingFavs = true
|
||||
await app.syncFavorites()
|
||||
await this.getArtistFeed()
|
||||
this.syncingFavs = false
|
||||
},
|
||||
async unfollow(id) {
|
||||
let index = this.followedArtists.indexOf(id)
|
||||
if (index > -1) {
|
||||
this.followedArtists.splice(index, 1)
|
||||
|
@ -71,6 +82,16 @@
|
|||
if (index2 > -1) {
|
||||
this.artists.splice(index2, 1)
|
||||
}
|
||||
await app.mk.api.v3.music(`/v1/me/favorites`, {
|
||||
"art[url]": "f",
|
||||
"ids[artists]": id,
|
||||
"l": app.mklang,
|
||||
"platform": "web"
|
||||
}, {
|
||||
fetchOptions: {
|
||||
method: "DELETE"
|
||||
}
|
||||
})
|
||||
this.getArtistFeed()
|
||||
},
|
||||
async getArtistFeed() {
|
||||
|
|
|
@ -194,32 +194,14 @@
|
|||
icon: "./assets/star.svg",
|
||||
name: app.getLz('action.favorite'),
|
||||
action: () => {
|
||||
app.mk.api.v3.music(`/v1/me/favorites`, {
|
||||
"art[url]": "f",
|
||||
"ids[artists]": app.artistPage.data.id,
|
||||
"l": app.mklang,
|
||||
"platform": "web"
|
||||
}, {
|
||||
fetchOptions: {
|
||||
method: "POST"
|
||||
}
|
||||
})
|
||||
app.setArtistFavorite(app.artistPage.data.id, true)
|
||||
}
|
||||
},
|
||||
removeFavorite: {
|
||||
icon: "./assets/star.svg",
|
||||
name: app.getLz('action.removeFavorite'),
|
||||
action: () => {
|
||||
app.mk.api.v3.music(`/v1/me/favorites`, {
|
||||
"art[url]": "f",
|
||||
"ids[artists]": app.artistPage.data.id,
|
||||
"l": app.mklang,
|
||||
"platform": "web"
|
||||
}, {
|
||||
fetchOptions: {
|
||||
method: "DELETE"
|
||||
}
|
||||
})
|
||||
app.setArtistFavorite(app.artistPage.data.id, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +223,7 @@
|
|||
}
|
||||
},
|
||||
favoriteActions[inFavorites ? "removeFavorite" : "favorite"],
|
||||
followActions[followAction],
|
||||
// followActions[followAction],
|
||||
{
|
||||
icon: "./assets/feather/share.svg",
|
||||
name: app.getLz('term.share'),
|
||||
|
|
|
@ -643,39 +643,11 @@
|
|||
app.copyToClipboard(res.data.data[0].attributes.url)
|
||||
})
|
||||
}
|
||||
},
|
||||
"follow": {
|
||||
name: app.getLz('action.follow'),
|
||||
icon: "./assets/feather/plus-circle.svg",
|
||||
hidden: false,
|
||||
action: () => {
|
||||
app.followArtistById(artistId, true)
|
||||
}
|
||||
},
|
||||
"unfollow": {
|
||||
name: app.getLz('action.unfollow'),
|
||||
icon: "./assets/feather/x-circle.svg",
|
||||
hidden: true,
|
||||
action: () => {
|
||||
app.followArtistById(artistId, false)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
app.showMenuPanel(menuItems, event)
|
||||
|
||||
if (artistId != null) {
|
||||
if (app.followingArtist(artistId)) {
|
||||
menuItems.items.follow.hidden = true
|
||||
menuItems.items.unfollow.hidden = false
|
||||
} else {
|
||||
menuItems.items.follow.hidden = false
|
||||
menuItems.items.unfollow.hidden = true
|
||||
}
|
||||
} else {
|
||||
menuItems.items.follow.hidden = true
|
||||
menuItems.items.unfollow.hidden = true
|
||||
}
|
||||
try {
|
||||
let rating = await app.getRating(self.data)
|
||||
if (rating == 0) {
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
<h3>{{app.getLz('home.artistsFeed')}}</h3>
|
||||
</div>
|
||||
<div class="col-auto nopadding flex-center">
|
||||
<button class="cd-btn-seeall" @click="syncFavorites()" v-if="!syncingFavs">{{app.getLz('home.syncFavorites')}}</button>
|
||||
<div class="spinner" style="height: 26px;" v-else></div>
|
||||
<button class="cd-btn-seeall" @click="app.appRoute('artist-feed')">{{app.getLz('term.seeAll')}}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -113,7 +115,8 @@
|
|||
page: "main",
|
||||
sectionsReady: [],
|
||||
year: new Date().getFullYear(),
|
||||
seenReplay: localStorage.getItem('seenReplay')
|
||||
seenReplay: localStorage.getItem('seenReplay'),
|
||||
syncingFavs: false
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
|
@ -128,6 +131,12 @@
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
async syncFavorites() {
|
||||
this.syncingFavs = true
|
||||
await app.syncFavorites()
|
||||
await this.getArtistFeed()
|
||||
this.syncingFavs = false
|
||||
},
|
||||
async seeAllRecentlyPlayed() {
|
||||
let hist = await app.mk.api.v3.music(`/v1/me/recent/played`, {
|
||||
l: this.$root.mklang,
|
||||
|
@ -188,7 +197,7 @@
|
|||
async getArtistFeed() {
|
||||
let artists = this.followedArtists
|
||||
let self = this
|
||||
|
||||
this.artistFeed = []
|
||||
let chunks = []
|
||||
for (let artistIdx = 0; artistIdx < artists.length; artistIdx += 50) {
|
||||
chunks.push(artists.slice(artistIdx, artistIdx + 50));
|
||||
|
|
|
@ -539,7 +539,7 @@
|
|||
icon: "./assets/feather/plus-circle.svg",
|
||||
hidden: false,
|
||||
action: () => {
|
||||
app.followArtistById(artistId, true)
|
||||
app.setArtistFavorite(artistId, true)
|
||||
}
|
||||
},
|
||||
"unfollow": {
|
||||
|
@ -547,7 +547,7 @@
|
|||
icon: "./assets/feather/x-circle.svg",
|
||||
hidden: true,
|
||||
action: () => {
|
||||
app.followArtistById(artistId, false)
|
||||
app.setArtistFavorite(artistId, false)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue