2018-08-11 07:47:10 +02:00
|
|
|
<template>
|
|
|
|
<content-with-heading>
|
2022-02-19 06:39:14 +01:00
|
|
|
<template #heading-left>
|
|
|
|
<div class="title is-4">
|
|
|
|
{{ playlist.name }}
|
|
|
|
</div>
|
2018-08-11 07:47:10 +02:00
|
|
|
</template>
|
2022-02-19 06:39:14 +01:00
|
|
|
<template #heading-right>
|
2019-02-20 09:22:17 +01:00
|
|
|
<div class="buttons is-centered">
|
2022-02-19 06:39:14 +01:00
|
|
|
<a
|
|
|
|
class="button is-small is-light is-rounded"
|
|
|
|
@click="show_playlist_details_modal = true"
|
|
|
|
>
|
|
|
|
<span class="icon"
|
|
|
|
><i class="mdi mdi-dots-horizontal mdi-18px"
|
|
|
|
/></span>
|
2019-02-20 09:22:17 +01:00
|
|
|
</a>
|
|
|
|
<a class="button is-small is-dark is-rounded" @click="play">
|
2022-02-19 06:39:14 +01:00
|
|
|
<span class="icon"><i class="mdi mdi-shuffle" /></span>
|
|
|
|
<span>Shuffle</span>
|
2019-02-20 09:22:17 +01:00
|
|
|
</a>
|
|
|
|
</div>
|
2018-08-11 07:47:10 +02:00
|
|
|
</template>
|
2022-02-19 06:39:14 +01:00
|
|
|
<template #content>
|
|
|
|
<p class="heading has-text-centered-mobile">
|
|
|
|
{{ playlist.tracks.total }} tracks
|
|
|
|
</p>
|
|
|
|
<spotify-list-item-track
|
|
|
|
v-for="(item, index) in tracks"
|
|
|
|
:key="item.track.id"
|
|
|
|
:track="item.track"
|
|
|
|
:album="item.track.album"
|
|
|
|
:position="index"
|
|
|
|
:context_uri="playlist.uri"
|
|
|
|
>
|
|
|
|
<template #actions>
|
2018-12-17 11:52:09 +01:00
|
|
|
<a @click="open_track_dialog(item.track)">
|
2022-02-19 06:39:14 +01:00
|
|
|
<span class="icon has-text-dark"
|
|
|
|
><i class="mdi mdi-dots-vertical mdi-18px"
|
|
|
|
/></span>
|
2018-12-17 11:52:09 +01:00
|
|
|
</a>
|
|
|
|
</template>
|
|
|
|
</spotify-list-item-track>
|
2022-02-19 06:39:14 +01:00
|
|
|
<VueEternalLoading v-if="offset < total" :load="load_next">
|
|
|
|
<template #no-more> . </template>
|
|
|
|
</VueEternalLoading>
|
|
|
|
<spotify-modal-dialog-track
|
|
|
|
:show="show_track_details_modal"
|
|
|
|
:track="selected_track"
|
|
|
|
:album="selected_track.album"
|
|
|
|
@close="show_track_details_modal = false"
|
|
|
|
/>
|
|
|
|
<spotify-modal-dialog-playlist
|
|
|
|
:show="show_playlist_details_modal"
|
|
|
|
:playlist="playlist"
|
|
|
|
@close="show_playlist_details_modal = false"
|
|
|
|
/>
|
2018-08-11 07:47:10 +02:00
|
|
|
</template>
|
|
|
|
</content-with-heading>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-02-19 06:18:01 +01:00
|
|
|
import ContentWithHeading from '@/templates/ContentWithHeading.vue'
|
|
|
|
import SpotifyListItemTrack from '@/components/SpotifyListItemTrack.vue'
|
|
|
|
import SpotifyModalDialogTrack from '@/components/SpotifyModalDialogTrack.vue'
|
|
|
|
import SpotifyModalDialogPlaylist from '@/components/SpotifyModalDialogPlaylist.vue'
|
2018-08-11 07:47:10 +02:00
|
|
|
import store from '@/store'
|
|
|
|
import webapi from '@/webapi'
|
|
|
|
import SpotifyWebApi from 'spotify-web-api-js'
|
2022-02-19 06:18:01 +01:00
|
|
|
import { VueEternalLoading } from '@ts-pro/vue-eternal-loading'
|
2018-08-11 07:47:10 +02:00
|
|
|
|
2022-02-19 06:18:01 +01:00
|
|
|
const PAGE_SIZE = 50
|
|
|
|
|
|
|
|
const dataObject = {
|
2018-08-11 07:47:10 +02:00
|
|
|
load: function (to) {
|
|
|
|
const spotifyApi = new SpotifyWebApi()
|
|
|
|
spotifyApi.setAccessToken(store.state.spotify.webapi_token)
|
|
|
|
return Promise.all([
|
2018-10-26 20:10:52 +02:00
|
|
|
spotifyApi.getPlaylist(to.params.playlist_id),
|
2022-02-19 06:39:14 +01:00
|
|
|
spotifyApi.getPlaylistTracks(to.params.playlist_id, {
|
|
|
|
limit: PAGE_SIZE,
|
|
|
|
offset: 0
|
|
|
|
})
|
2018-08-11 07:47:10 +02:00
|
|
|
])
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (vm, response) {
|
|
|
|
vm.playlist = response[0]
|
|
|
|
vm.tracks = []
|
|
|
|
vm.total = 0
|
|
|
|
vm.offset = 0
|
|
|
|
vm.append_tracks(response[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'SpotifyPagePlaylist',
|
2022-02-19 06:39:14 +01:00
|
|
|
components: {
|
|
|
|
ContentWithHeading,
|
|
|
|
SpotifyListItemTrack,
|
|
|
|
SpotifyModalDialogTrack,
|
|
|
|
SpotifyModalDialogPlaylist,
|
|
|
|
VueEternalLoading
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeRouteEnter(to, from, next) {
|
|
|
|
dataObject.load(to).then((response) => {
|
|
|
|
next((vm) => dataObject.set(vm, response))
|
|
|
|
})
|
|
|
|
},
|
|
|
|
beforeRouteUpdate(to, from, next) {
|
|
|
|
const vm = this
|
|
|
|
dataObject.load(to).then((response) => {
|
|
|
|
dataObject.set(vm, response)
|
|
|
|
next()
|
|
|
|
})
|
|
|
|
},
|
2018-08-11 07:47:10 +02:00
|
|
|
|
2022-02-19 06:39:14 +01:00
|
|
|
data() {
|
2018-08-11 07:47:10 +02:00
|
|
|
return {
|
2018-12-17 11:52:09 +01:00
|
|
|
playlist: { tracks: {} },
|
2018-08-11 07:47:10 +02:00
|
|
|
tracks: [],
|
|
|
|
total: 0,
|
2018-12-17 11:52:09 +01:00
|
|
|
offset: 0,
|
|
|
|
|
|
|
|
show_track_details_modal: false,
|
2019-02-20 09:22:17 +01:00
|
|
|
selected_track: {},
|
|
|
|
|
|
|
|
show_playlist_details_modal: false
|
2018-08-11 07:47:10 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2022-02-19 06:18:01 +01:00
|
|
|
load_next: function ({ loaded }) {
|
2018-08-11 07:47:10 +02:00
|
|
|
const spotifyApi = new SpotifyWebApi()
|
|
|
|
spotifyApi.setAccessToken(this.$store.state.spotify.webapi_token)
|
2022-02-19 06:39:14 +01:00
|
|
|
spotifyApi
|
|
|
|
.getPlaylistTracks(this.playlist.id, {
|
|
|
|
limit: PAGE_SIZE,
|
|
|
|
offset: this.offset
|
|
|
|
})
|
|
|
|
.then((data) => {
|
|
|
|
this.append_tracks(data)
|
|
|
|
loaded(data.items.length, PAGE_SIZE)
|
|
|
|
})
|
2018-08-11 07:47:10 +02:00
|
|
|
},
|
|
|
|
|
2022-02-19 06:18:01 +01:00
|
|
|
append_tracks: function (data) {
|
2018-08-11 07:47:10 +02:00
|
|
|
this.tracks = this.tracks.concat(data.items)
|
|
|
|
this.total = data.total
|
|
|
|
this.offset += data.limit
|
|
|
|
},
|
|
|
|
|
|
|
|
play: function () {
|
|
|
|
this.show_details_modal = false
|
2018-11-06 21:44:01 +01:00
|
|
|
webapi.player_play_uri(this.playlist.uri, true)
|
2018-12-17 11:52:09 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
open_track_dialog: function (track) {
|
|
|
|
this.selected_track = track
|
|
|
|
this.show_track_details_modal = true
|
2018-08-11 07:47:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2022-02-19 06:39:14 +01:00
|
|
|
<style></style>
|