very basic songs search, checks if downloaded.next is undefined

This commit is contained in:
booploops 2021-12-04 13:44:26 -08:00
parent 6f856fab2f
commit 6e5fc7fb0b
2 changed files with 69 additions and 51 deletions

View file

@ -268,10 +268,12 @@
style="width:100%;"
spellcheck="false"
placeholder="Search..."
@input="searchLibrarySongs"
v-model="library.songs.search"
class="search-input">
</div>
<mediaitem-list-item :item="item"
v-for="item in library.songs.listing"></mediaitem-list-item>
v-for="item in library.songs.displayListing"></mediaitem-list-item>
</template>
</div>
</template>
@ -460,9 +462,9 @@
<template>
<div @click="app.playMediaItemById(item.attributes.playParams.id ?? item.id, item.attributes.playParams.kind ?? item.type, item.attributes.playParams.isLibrary ?? false, item.attributes.url)"
class="cd-mediaitem-list-item">
<div class="artwork"
<div class="artwork" v-if="item.attributes.artwork"
:class="{'round': item.type == 'artists'}"
:style="{'--artwork': app.getMediaItemArtwork(item.attributes.artwork.url, 34)}
:style="{'--artwork': app.getMediaItemArtwork(item.attributes.artwork.url ? item.attributes.artwork.url : '', 34)}
"></div>
<div class="info-rect">
<div class="title text-overflow-elipsis">

View file

@ -108,6 +108,8 @@ const app = new Vue({
songs: {
listing: [],
meta: {total: 0, progress: 0},
search: "",
displayListing: [],
downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete
},
albums: {
@ -121,9 +123,7 @@ const app = new Vue({
},
chrome: {
artworkReady: false,
userinfo: {
},
userinfo: {},
menuOpened: false,
maximized: false
},
@ -152,7 +152,18 @@ const app = new Vue({
})
document.body.removeAttribute("loading")
},
searchLibrarySongs() {
let self = this
if (this.library.songs.search == "") {
this.library.songs.displayListing = this.library.songs.listing
} else {
this.library.songs.displayListing = this.library.songs.listing.filter(item => {
if(item.attributes.name.toLowerCase().includes(this.library.songs.search.toLowerCase())) {
return item
}
})
}
},
getSidebarItemClass(page) {
if (this.page == page) {
return ["active"]
@ -183,6 +194,7 @@ const app = new Vue({
return
}
this.library.songs.downloadState = 1
function downloadChunk() {
if (downloaded == null) {
app.mk.api.library.songs("", {limit: 100}, {includeResponseMeta: !0}).then((response) => {
@ -194,20 +206,26 @@ const app = new Vue({
})
}
}
function processChunk(response) {
downloaded = response
library = library.concat(downloaded.data)
self.library.songs.meta.total = downloaded.meta.total
self.library.songs.meta.progress = library.length
if (downloaded.meta.total > library.length) {
if(typeof downloaded.next == "undefined") {
console.log("downloaded.next is undefined")
}
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
console.log(`downloading next chunk - ${library.length} songs so far`)
downloadChunk()
} else {
self.library.songs.listing = library
self.library.songs.downloadState = 2
self.searchLibrarySongs()
console.log(library)
}
}
downloadChunk()
},
async getLibrarySongs() {
@ -323,8 +341,7 @@ const app = new Vue({
} else {
return "";
}
}
catch (e){
} catch (e) {
return ""
// Does not work
// this.mk.api.library.song(this.mk.nowPlayingItem.id).then((data) => {
@ -349,8 +366,7 @@ const app = new Vue({
} else {
return "";
}
}
catch (e){
} catch (e) {
return ""
// Does not work
// this.mk.api.library.song(this.mk.nowPlayingItem.id).then((data) => {