fix: update Next Up page

master
qier222 4 years ago
parent f6c36fbcac
commit 0665f53f0d

@ -3,14 +3,23 @@
<h1>{{ $t("next.nowPlaying") }}</h1> <h1>{{ $t("next.nowPlaying") }}</h1>
<TrackList <TrackList
:tracks="[currentTrack]" :tracks="[currentTrack]"
:type="'playlist'" type="playlist"
dbclickTrackFunc="none" dbclickTrackFunc="none"
/> />
<h1 v-show="playNextList.length > 0"></h1>
<TrackList
:tracks="playNextTracks"
type="playlist"
:highlightPlayingTrack="false"
dbclickTrackFunc="playTrackOnListByID"
itemKey="id+index"
v-show="playNextList.length > 0"
/>
<h1>{{ $t("next.nextUp") }}</h1> <h1>{{ $t("next.nextUp") }}</h1>
<TrackList <TrackList
:tracks="sortedTracks" :tracks="filteredTracks"
:type="'playlist'" type="playlist"
:highlightPlayingTrack="false"
dbclickTrackFunc="playTrackOnListByID" dbclickTrackFunc="playTrackOnListByID"
/> />
</div> </div>
@ -39,20 +48,20 @@ export default {
playerShuffle() { playerShuffle() {
return this.player.shuffle; return this.player.shuffle;
}, },
sortedTracks() { filteredTracks() {
function compare(property) { let trackIDs = this.player.list.slice(
return function (obj1, obj2) { this.player.current + 1,
var value1 = obj1[property]; this.player.current + 100
var value2 = obj2[property]; );
return value1 - value2; return this.tracks.filter((t) => trackIDs.includes(t.id));
}; },
} playNextList() {
return this.tracks return this.player.playNextList;
.filter( },
(t) => this.player.list.find((t2) => t2.id === t.id) !== undefined playNextTracks() {
) return this.playNextList.map((tid) => {
.filter((t) => t.sort > this.player.currentTrack.sort) return this.tracks.find((t) => t.id === tid);
.sort(compare("sort")); });
}, },
}, },
watch: { watch: {
@ -60,36 +69,35 @@ export default {
this.loadTracks(); this.loadTracks();
}, },
playerShuffle() { playerShuffle() {
this.tracks = this.tracks.map((t) => { this.loadTracks();
t.sort = this.player.list.find((t2) => t.id === t2.id).sort; },
return t; playNextList() {
}); this.loadTracks();
}, },
}, },
methods: { methods: {
...mapActions(["playTrackOnListByID"]), ...mapActions(["playTrackOnListByID"]),
loadTracks() { loadTracks() {
console.time("loadTracks"); // 100
let trackIDs = this.player.list.slice(
this.player.current + 1,
this.player.current + 100
);
// playNextListtrackIDs
trackIDs.push(...this.playNextList);
//
let loadedTrackIDs = this.tracks.map((t) => t.id); let loadedTrackIDs = this.tracks.map((t) => t.id);
let basicTracks = this.player.list
.filter(
(t) =>
t.sort > this.player.currentTrack.sort &&
t.sort <= this.player.currentTrack.sort + 100
)
.filter((t) => loadedTrackIDs.includes(t.id) === false);
let trackIDs = basicTracks.map((t) => t.id);
if (trackIDs.length > 0) { if (trackIDs.length > 0) {
getTrackDetail(trackIDs.join(",")).then((data) => { getTrackDetail(trackIDs.join(",")).then((data) => {
let newTracks = data.songs.map((t) => { let newTracks = data.songs.filter(
t.sort = this.player.list.find((t2) => t2.id == t.id).sort; (t) => !loadedTrackIDs.includes(t.id)
return t; );
});
this.tracks.push(...newTracks); this.tracks.push(...newTracks);
}); });
} }
console.timeEnd("loadTracks");
}, },
}, },
activated() { activated() {
@ -99,9 +107,6 @@ export default {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.next-tracks {
width: 78vw;
}
h1 { h1 {
margin-top: 36px; margin-top: 36px;
margin-bottom: 18px; margin-bottom: 18px;

Loading…
Cancel
Save