follow has been migrated to favorites

This commit is contained in:
booploops 2022-06-09 21:25:38 -07:00
parent 05b6ea112e
commit d7b314e0f5
9 changed files with 257 additions and 222 deletions

View file

@ -193,6 +193,8 @@
"term.confirmLogout": "Are you sure you want to logout?", "term.confirmLogout": "Are you sure you want to logout?",
"term.creditDesignedBy": "Designed by ${authorUsername}", "term.creditDesignedBy": "Designed by ${authorUsername}",
"term.discNumber": "Disc ${discNumber}", "term.discNumber": "Disc ${discNumber}",
"home.syncFavorites": "Sync Favorites",
"home.syncFavorites.gettingArtists": "Getting Favorited Artists...",
"home.title": "Home", "home.title": "Home",
"home.recentlyPlayed": "Recently Played", "home.recentlyPlayed": "Recently Played",
"home.recentlyAdded": "Recently Added", "home.recentlyAdded": "Recently Added",

View file

@ -516,7 +516,8 @@ const app = new Vue({
window.location.hash = `#charts/top` window.location.hash = `#charts/top`
} else { } else {
const id = url.split("id=")[1]; const id = url.split("id=")[1];
window.location.hash = `#groupings/${id}`} window.location.hash = `#groupings/${id}`
}
}, },
navigateForward() { navigateForward() {
history.forward() history.forward()
@ -841,7 +842,8 @@ const app = new Vue({
user: `${user.username}#${user.discriminator}`, user: `${user.username}#${user.discriminator}`,
userid: user.id userid: user.id
})); }));
}}) }
})
ipcRenderer.on('getUpdatedLocalList', (event, data) => { ipcRenderer.on('getUpdatedLocalList', (event, data) => {
console.log("cider-local", 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) { async refreshPlaylists(localOnly = false, useCachedPlaylists = true) {
let self = this let self = this
let trackMap = this.cfg.advanced.playlistTrackMapping let trackMap = this.cfg.advanced.playlistTrackMapping
@ -2038,16 +2100,6 @@ const app = new Vue({
this.getArtistFromID(id) this.getArtistFromID(id)
//this.getTypeFromID("artist",id,isLibrary,query) //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) { followingArtist(id) {
console.debug(`check for ${id}`) console.debug(`check for ${id}`)
return this.cfg.home.followedArtists.includes(id) return this.cfg.home.followedArtists.includes(id)

View file

@ -6,8 +6,8 @@
<div class="artist-chip__name"> <div class="artist-chip__name">
<span>{{ item.attributes.name }}</span> <span>{{ item.attributes.name }}</span>
</div> </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.setArtistFavorite(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, false)" title="Following" v-else class="artist-chip__follow codicon codicon-check"></button>
</div> </div>
</script> </script>

View file

@ -534,19 +534,16 @@
let followActions = { let followActions = {
follow: { follow: {
icon: "./assets/feather/plus-circle.svg", icon: "./assets/feather/plus-circle.svg",
name: app.getLz('action.follow'), name: app.getLz('action.favorite'),
action: () => { action: () => {
self.app.cfg.home.followedArtists.push(this.item.id) self.$root.setArtistFavorite(this.item.id, true)
} }
}, },
unfollow: { unfollow: {
icon: "./assets/feather/x-circle.svg", icon: "./assets/feather/x-circle.svg",
name: app.getLz('action.unfollow'), name: app.getLz('action.removeFavorite'),
action: () => { action: () => {
let index = self.app.cfg.home.followedArtists.indexOf(this.item.id) self.$root.setArtistFavorite(this.item.id, false)
if (index > -1) {
self.app.cfg.home.followedArtists.splice(index, 1)
}
} }
} }
} }

View file

@ -7,6 +7,10 @@
<div class="col nopadding"> <div class="col nopadding">
<h3>{{app.getLz('home.followedArtists')}}</h3> <h3>{{app.getLz('home.followedArtists')}}</h3>
</div> </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> </div>
<vue-horizontal> <vue-horizontal>
<div v-for="artist in artists" style="margin: 6px;"> <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;"> <button @click="unfollow(artist.id)" class="md-btn md-btn-glyph" style="display:flex;">
<div class="sidebar-icon"> <div class="sidebar-icon">
<div class="svg-icon" :style="{'--url': 'url(./assets/feather/x-circle.svg)'}"></div> <div class="svg-icon" :style="{'--url': 'url(./assets/feather/x-circle.svg)'}"></div>
</div> {{app.getLz('action.unfollow')}} </div> {{app.getLz('action.removeFavorite')}}
</button> </button>
</div> </div>
</vue-horizontal> </vue-horizontal>
@ -53,7 +57,8 @@
app: this.$root, app: this.$root,
followedArtists: this.$root.cfg.home.followedArtists, followedArtists: this.$root.cfg.home.followedArtists,
artistFeed: [], artistFeed: [],
artists: [] artists: [],
syncingFavs: false
} }
}, },
async mounted() { async mounted() {
@ -61,7 +66,13 @@
await this.getArtistFeed() await this.getArtistFeed()
}, },
methods: { 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) let index = this.followedArtists.indexOf(id)
if (index > -1) { if (index > -1) {
this.followedArtists.splice(index, 1) this.followedArtists.splice(index, 1)
@ -71,6 +82,16 @@
if (index2 > -1) { if (index2 > -1) {
this.artists.splice(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() this.getArtistFeed()
}, },
async getArtistFeed() { async getArtistFeed() {

View file

@ -194,32 +194,14 @@
icon: "./assets/star.svg", icon: "./assets/star.svg",
name: app.getLz('action.favorite'), name: app.getLz('action.favorite'),
action: () => { action: () => {
app.mk.api.v3.music(`/v1/me/favorites`, { app.setArtistFavorite(app.artistPage.data.id, true)
"art[url]": "f",
"ids[artists]": app.artistPage.data.id,
"l": app.mklang,
"platform": "web"
}, {
fetchOptions: {
method: "POST"
}
})
} }
}, },
removeFavorite: { removeFavorite: {
icon: "./assets/star.svg", icon: "./assets/star.svg",
name: app.getLz('action.removeFavorite'), name: app.getLz('action.removeFavorite'),
action: () => { action: () => {
app.mk.api.v3.music(`/v1/me/favorites`, { app.setArtistFavorite(app.artistPage.data.id, false)
"art[url]": "f",
"ids[artists]": app.artistPage.data.id,
"l": app.mklang,
"platform": "web"
}, {
fetchOptions: {
method: "DELETE"
}
})
} }
} }
} }
@ -241,7 +223,7 @@
} }
}, },
favoriteActions[inFavorites ? "removeFavorite" : "favorite"], favoriteActions[inFavorites ? "removeFavorite" : "favorite"],
followActions[followAction], // followActions[followAction],
{ {
icon: "./assets/feather/share.svg", icon: "./assets/feather/share.svg",
name: app.getLz('term.share'), name: app.getLz('term.share'),

View file

@ -643,39 +643,11 @@
app.copyToClipboard(res.data.data[0].attributes.url) 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) 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 { try {
let rating = await app.getRating(self.data) let rating = await app.getRating(self.data)
if (rating == 0) { if (rating == 0) {

View file

@ -26,6 +26,8 @@
<h3>{{app.getLz('home.artistsFeed')}}</h3> <h3>{{app.getLz('home.artistsFeed')}}</h3>
</div> </div>
<div class="col-auto nopadding flex-center"> <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> <button class="cd-btn-seeall" @click="app.appRoute('artist-feed')">{{app.getLz('term.seeAll')}}</button>
</div> </div>
</div> </div>
@ -113,7 +115,8 @@
page: "main", page: "main",
sectionsReady: [], sectionsReady: [],
year: new Date().getFullYear(), year: new Date().getFullYear(),
seenReplay: localStorage.getItem('seenReplay') seenReplay: localStorage.getItem('seenReplay'),
syncingFavs: false
} }
}, },
async mounted() { async mounted() {
@ -128,6 +131,12 @@
} }
}, },
methods: { methods: {
async syncFavorites() {
this.syncingFavs = true
await app.syncFavorites()
await this.getArtistFeed()
this.syncingFavs = false
},
async seeAllRecentlyPlayed() { async seeAllRecentlyPlayed() {
let hist = await app.mk.api.v3.music(`/v1/me/recent/played`, { let hist = await app.mk.api.v3.music(`/v1/me/recent/played`, {
l: this.$root.mklang, l: this.$root.mklang,
@ -188,7 +197,7 @@
async getArtistFeed() { async getArtistFeed() {
let artists = this.followedArtists let artists = this.followedArtists
let self = this let self = this
this.artistFeed = []
let chunks = [] let chunks = []
for (let artistIdx = 0; artistIdx < artists.length; artistIdx += 50) { for (let artistIdx = 0; artistIdx < artists.length; artistIdx += 50) {
chunks.push(artists.slice(artistIdx, artistIdx + 50)); chunks.push(artists.slice(artistIdx, artistIdx + 50));

View file

@ -539,7 +539,7 @@
icon: "./assets/feather/plus-circle.svg", icon: "./assets/feather/plus-circle.svg",
hidden: false, hidden: false,
action: () => { action: () => {
app.followArtistById(artistId, true) app.setArtistFavorite(artistId, true)
} }
}, },
"unfollow": { "unfollow": {
@ -547,7 +547,7 @@
icon: "./assets/feather/x-circle.svg", icon: "./assets/feather/x-circle.svg",
hidden: true, hidden: true,
action: () => { action: () => {
app.followArtistById(artistId, false) app.setArtistFavorite(artistId, false)
} }
}, },
} }