fix for collection list on v3

This commit is contained in:
booploops 2022-01-18 02:43:15 -08:00
parent cd48e25acc
commit ea9a11ce25
2 changed files with 54 additions and 64 deletions

View file

@ -249,6 +249,11 @@ const app = new Vue({
start: 0, start: 0,
end: 0 end: 0
}, },
v3: {
requestBody: {
platform: "web"
}
},
tmpVar: [], tmpVar: [],
notification: false, notification: false,
chrome: { chrome: {
@ -881,15 +886,18 @@ const app = new Vue({
}) })
} }
}, },
async showCollection(response, title, type) { async showCollection(response, title, type, requestBody = {}) {
let self = this let self = this
console.log(response)
this.collectionList.requestBody = {}
this.collectionList.response = response this.collectionList.response = response
this.collectionList.title = title this.collectionList.title = title
this.collectionList.type = type this.collectionList.type = type
this.collectionList.requestBody = requestBody
app.appRoute("collection-list") app.appRoute("collection-list")
}, },
async showArtistView(artist, title, view) { async showArtistView(artist, title, view) {
let response = (await app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/artists/${artist}/view/${view}`)).data let response = (await app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/artists/${artist}/view/${view}`,{}, {includeResponseMeta: !0})).data
console.log(response) console.log(response)
await this.showCollection(response, title, "artists") await this.showCollection(response, title, "artists")
}, },
@ -898,7 +906,8 @@ const app = new Vue({
await this.showCollection(response, title, "record-labels") await this.showCollection(response, title, "record-labels")
}, },
async showSearchView(term, group, title) { async showSearchView(term, group, title) {
let response = await app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/search?term=${term}`, {
let requestBody = {
platform: "web", platform: "web",
groups: group, groups: group,
types: "activities,albums,apple-curators,artists,curators,editorial-items,music-movies,music-videos,playlists,songs,stations,tv-episodes,uploaded-videos,record-labels", types: "activities,albums,apple-curators,artists,curators,editorial-items,music-movies,music-videos,playlists,songs,stations,tv-episodes,uploaded-videos,record-labels",
@ -924,14 +933,18 @@ const app = new Vue({
resource: ["autos"] resource: ["autos"]
}, },
groups: group groups: group
}
let response = await app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/search?term=${term}`, requestBody , {
includeResponseMeta: !0
}) })
console.log('searchres', response) console.log('searchres', response)
let responseFormat = { let responseFormat = {
data: response.data.results[group].data, data: response.data.results[group].data,
next: response.data.results[group].data, next: response.data.results[group].next,
groups: group groups: group
} }
await this.showCollection(responseFormat, title, "search") await this.showCollection(responseFormat, title, "search", requestBody)
}, },
async getPlaylistContinuous(response, transient = false) { async getPlaylistContinuous(response, transient = false) {
response = response.data.data[0] response = response.data.data[0]

View file

@ -14,13 +14,16 @@
<mediaitem-square v-else :item="item" :type="getKind(item)"></mediaitem-square> <mediaitem-square v-else :item="item" :type="getKind(item)"></mediaitem-square>
</template> </template>
</template> </template>
<button v-if="triggerEnabled" style="opacity:0;height: 32px;" v-observe-visibility="{callback: visibilityChanged}">Show More</button> <button v-if="triggerEnabled" style="opacity:0;height: 32px;"
v-observe-visibility="{callback: visibilityChanged}">Show More
</button>
</div> </div>
<transition name="fabfade"> <transition name="fabfade">
<button class="top-fab" v-show="showFab" @click="scrollToTop()"> <button class="top-fab" v-show="showFab" @click="scrollToTop()">
<%- include("../svg/arrow-up.svg") %> <%- include("../svg/arrow-up.svg") %>
</button> </button>
</transition> </transition>
<div class="well" v-show="loading"><div class="spinner"></div></div>
</div> </div>
</script> </script>
<script> <script>
@ -47,16 +50,17 @@
canSeeTrigger: false, canSeeTrigger: false,
showFab: false, showFab: false,
commonKind: "song", commonKind: "song",
api: this.$root.mk.api api: this.$root.mk.api,
loading: false
} }
}, },
methods: { methods: {
getKind(item) { getKind(item) {
if(typeof item.kind != "undefined") { if (typeof item.kind != "undefined") {
this.commonKind = item.kind; this.commonKind = item.kind;
return item.kind return item.kind
} }
if(typeof item.attributes.playParams != "undefined") { if (typeof item.attributes.playParams != "undefined") {
this.commonKind = item.attributes.playParams.kind this.commonKind = item.attributes.playParams.kind
return item.attributes.playParams.kind return item.attributes.playParams.kind
} }
@ -71,73 +75,46 @@
}) })
}, },
getNext() { getNext() {
// if this.data.next is not null, then we can run this.data.next() and concat to this.data.data to get the next page let self = this
switch(this.type) {
default:
case "artists":
if (this.data.next && this.triggerEnabled) {
this.triggerEnabled = false; this.triggerEnabled = false;
this.loading = true
let nextFn = (data => { if (this.data.next == "undefined") {
console.log(data); return
this.data.next = data.next;
this.data.data = this.data.data.concat(data.data);
this.triggerEnabled = true;
});
if(typeof this.data.next == "function") {
this.data.next().then(data => nextFn(data));
}else{
this.api.v3.music(this.data.next).then(data => nextFn(data));
}
}else{
console.log("No next page");
this.triggerEnabled = false;
}
break;
case "search":
if (this.data.next && this.triggerEnabled) {
this.triggerEnabled = false;
this.data.next().then(data => {
console.log(data);
this.data.next = data[this.data.groups].next;
this.data.data = this.data.data.concat(data[this.data.groups].data.data);
this.triggerEnabled = true;
});
}else{
console.log("No next page");
this.triggerEnabled = false;
}
break;
case "listen_now":
case "curator":
if (this.data.next && this.triggerEnabled) {
this.triggerEnabled = false;
app.mk.api.v3.music(this.data.next).then(data => {
console.log(data);
this.data.next = data.data.next;
this.data.data = this.data.data.concat(data.data.data);
this.triggerEnabled = true;
});
}else{
console.log("No next page");
this.triggerEnabled = false;
}
break;
} }
this.api.v3.music(this.data.next, app.collectionList.requestBody).then((response) => {
if (!app.collectionList.response.groups) {
if (response.data.next) {
this.data.data = this.data.data.concat(response.data.data);
this.data.next = response.data.next;
this.triggerEnabled = true;
this.loading = false
}
}else{
if (response.data.results[app.collectionList.response.groups].next) {
this.data.data = this.data.data.concat(response.data.results[app.collectionList.response.groups].data);
this.data.next = response.data.results[app.collectionList.response.groups].next;
this.triggerEnabled = true;
this.loading = false
}
}
})
}, },
headerVisibility: function (isVisible, entry) { headerVisibility: function (isVisible, entry) {
if(isVisible) { if (isVisible) {
this.showFab = false; this.showFab = false;
}else{ } else {
this.showFab = true; this.showFab = true;
} }
}, },
visibilityChanged: function (isVisible, entry) { visibilityChanged: function (isVisible, entry) {
if(isVisible) { if (isVisible) {
this.canSeeTrigger = true; this.canSeeTrigger = true;
this.getNext(); this.getNext();
}else{ } else {
this.canSeeTrigger = false; this.canSeeTrigger = false;
} }
} }