adds friend badges to mediaitem square, working on adding to playlists/albums

This commit is contained in:
booploops 2021-12-30 06:05:19 -08:00
parent a662192b2d
commit 4390493a9f
4 changed files with 138 additions and 10 deletions

View file

@ -259,6 +259,10 @@ const app = new Vue({
addToPlaylist: false, addToPlaylist: false,
spatialProperties: false spatialProperties: false
}, },
socialBadges: {
badgeMap: {},
version: ""
}
}, },
watch: { watch: {
cfg: { cfg: {
@ -282,6 +286,17 @@ const app = new Vue({
}, },
}, },
methods: { methods: {
getSocialBadges(cb = ()=>{}) {
let self = this
try {
app.mk.api.socialBadgingMap().then(data=>{
self.socialBadges.badgeMap = data.badgingMap
cb(data.badgingMap)
})
}catch(ex) {
this.socialBadges.badgeMap = {}
}
},
addFavorite(id, type) { addFavorite(id, type) {
this.cfg.home.favoriteItems.push({ this.cfg.home.favoriteItems.push({
id: id, id: id,
@ -555,6 +570,7 @@ const app = new Vue({
} }
setTimeout(() => { setTimeout(() => {
this.getSocialBadges()
this.getBrowsePage(); this.getBrowsePage();
this.$forceUpdate() this.$forceUpdate()
}, 500) }, 500)

View file

@ -2053,6 +2053,34 @@ input[type="range"].web-slider.display--small::-webkit-slider-thumb {
} }
} }
.friends-info {
display: flex;
flex-flow: column;
.badge-container {
display: flex;
flex-flow: wrap;
.socialBadge {
width: 40px;
height: 40px;
border-radius: 100%;
overflow: hidden;
box-shadow: var(--mediaItemShadow-ShadowSubtle);
transition: transform .2s var(--appleEase);
margin: 6px;
&:hover {
transform: scale(1.2);
}
}
}
.friends-name {
text-align: center;
font-size: 0.9em;
margin: 8px;
}
}
.playlist-time { .playlist-time {
font-size: 0.9em; font-size: 0.9em;
margin: 6px; margin: 6px;
@ -2892,6 +2920,22 @@ input[type="range"].web-slider.display--small::-webkit-slider-thumb {
} }
} }
.badge-container {
transition: opacity 0.1s var(--appleEase);
opacity: 1;
.socialBadge {
width: 32px;
height: 32px;
position: absolute;
right: 14px;
bottom: 14px;
border-radius: 100%;
overflow: hidden;
z-index: 2;
pointer-events: none;
}
}
> .play-btn, > .play-btn,
> .menu-btn { > .menu-btn {
opacity: 0; opacity: 0;
@ -2922,7 +2966,9 @@ input[type="range"].web-slider.display--small::-webkit-slider-thumb {
} }
&:hover { &:hover {
> .badge-container {
opacity: 0;
}
> .play-btn, > .play-btn,
> .menu-btn { > .menu-btn {
opacity: 1; opacity: 1;

View file

@ -16,6 +16,13 @@
@click="contextMenu"><%- include("../svg/more.svg") %></button> @click="contextMenu"><%- include("../svg/more.svg") %></button>
<button class="play-btn" v-if="!noplay.includes(item.type)" <button class="play-btn" v-if="!noplay.includes(item.type)"
@click="app.playMediaItem(item)"><%- include("../svg/play.svg") %></button> @click="app.playMediaItem(item)"><%- include("../svg/play.svg") %></button>
<div class="badge-container" v-if="itemBadges.length != 0">
<div class="socialBadge" v-for="badge in itemBadges.limit(1)">
<mediaitem-artwork
:url="badge.attributes.artwork.url"
:size="32"></mediaitem-artwork>
</div>
</div>
</div> </div>
<div class="title item-navigate text-overflow-elipsis" @click.self='app.routeView(item)'> <div class="title item-navigate text-overflow-elipsis" @click.self='app.routeView(item)'>
{{ item.attributes.name }} {{ item.attributes.name }}
@ -54,10 +61,28 @@
guid: this.uuidv4(), guid: this.uuidv4(),
noplay: ["apple-curators"], noplay: ["apple-curators"],
nomenu: ["artists", "stations", "apple-curators"], nomenu: ["artists", "stations", "apple-curators"],
app: this.$root app: this.$root,
badges: this.$root.socialBadges.badgeMap,
itemBadges: []
} }
}, },
async mounted() {
await this.getBadges()
},
methods: { methods: {
async getBadges() {
let self = this
if(this.badges[this.item.attributes.playParams.id ?? this.item.id]) {
let friends = this.badges[this.item.attributes.playParams.id ?? this.item.id]
if(friends) {
friends.forEach(function (friend) {
self.app.mk.api.socialProfile(friend).then(data => {
self.itemBadges.push(data)
})
})
}
}
},
revisedRandId() { revisedRandId() {
return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(2, 10); return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(2, 10);
}, },

View file

@ -83,6 +83,17 @@
</div> </div>
</div> </div>
<div class="friends-info" v-if="itemBadges.length != 0">
<div class="well">
<div class="badge-container">
<div class="socialBadge" :title="`${badge.attributes.name} - @${badge.attributes.handle}`" v-for="badge in itemBadges">
<mediaitem-artwork
:url="badge.attributes.artwork.url"
:size="60"></mediaitem-artwork>
</div>
</div>
</div>
</div>
<div class="playlist-time"> <div class="playlist-time">
{{getFormattedDate(data.attributes.releaseDate)}} {{getFormattedDate(data.attributes.releaseDate)}}
</div> </div>
@ -106,7 +117,9 @@
drag: false, drag: false,
nameEditing: false, nameEditing: false,
inLibrary: null, inLibrary: null,
app: this.$root app: this.$root,
itemBadges: [],
badgesRequested: false
} }
}, },
mounted: function () { mounted: function () {
@ -117,9 +130,35 @@
watch: { watch: {
data: function () { data: function () {
this.isInLibrary() this.isInLibrary()
this.getBadges()
} }
}, },
methods: { methods: {
getBadges() {
return
if(this.badgesRequested) {
return
}
this.badgesRequested = true
this.itemBadges = []
let self = this
var id = 0
try {
id = this.data.attributes.playParams.id
} catch (e) {
id = this.data.id
}
this.$root.getSocialBadges((badges) => {
let friends = badges[id]
if(friends) {
friends.forEach(function (friend) {
self.app.mk.api.socialProfile(friend).then(data => {
self.itemBadges.push(data)
})
})
}
})
},
async isInLibrary() { async isInLibrary() {
if (this.data.type && !this.data.type.includes("library")) { if (this.data.type && !this.data.type.includes("library")) {
// please keep using vars here // please keep using vars here
@ -228,14 +267,16 @@
}, },
getFormattedDate: function (date) { getFormattedDate: function (date) {
if (date == null || date === "") return ""; if (date == null || date === "") return "";
try{ try {
var releaseDate = new Date(date); var releaseDate = new Date(date);
month = new Intl.DateTimeFormat('en-US', { month: 'long'}).format(releaseDate); month = new Intl.DateTimeFormat('en-US', {month: 'long'}).format(releaseDate);
date = releaseDate.getDate(); date = releaseDate.getDate();
year = releaseDate.getFullYear(); year = releaseDate.getFullYear();
return date + " " + month + " " + year; return date + " " + month + " " + year;
} catch (e){ return ""} } catch (e) {
return ""
}
} }
} }
}) })