2018-08-11 07:47:10 +02:00
|
|
|
<template>
|
2023-06-23 22:23:32 +02:00
|
|
|
<div class="fd-page">
|
|
|
|
<content-with-heading>
|
|
|
|
<template #heading-left>
|
|
|
|
<div class="title is-4" v-text="playlist.name" />
|
|
|
|
</template>
|
|
|
|
<template #heading-right>
|
|
|
|
<div class="buttons is-centered">
|
|
|
|
<a
|
|
|
|
class="button is-small is-light is-rounded"
|
|
|
|
@click="show_playlist_details_modal = true"
|
|
|
|
>
|
2023-06-30 21:41:40 +02:00
|
|
|
<mdicon class="icon" name="dots-horizontal" size="16" />
|
2018-12-17 11:52:09 +01:00
|
|
|
</a>
|
2023-06-23 22:23:32 +02:00
|
|
|
<a class="button is-small is-dark is-rounded" @click="play">
|
2023-06-30 21:41:40 +02:00
|
|
|
<mdicon class="icon" name="shuffle" size="16" />
|
2023-06-23 22:23:32 +02:00
|
|
|
<span v-text="$t('page.spotify.playlist.shuffle')" />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<template #content>
|
|
|
|
<p
|
|
|
|
class="heading has-text-centered-mobile"
|
|
|
|
v-text="
|
|
|
|
$t('page.spotify.playlist.count', { count: playlist.tracks.total })
|
|
|
|
"
|
|
|
|
/>
|
2023-07-18 15:19:24 +02:00
|
|
|
<list-item-track-spotify
|
2023-06-23 22:23:32 +02:00
|
|
|
v-for="track in tracks"
|
|
|
|
:key="track.id"
|
|
|
|
:track="track"
|
|
|
|
:position="track.position"
|
|
|
|
:context_uri="playlist.uri"
|
|
|
|
>
|
|
|
|
<template #actions>
|
|
|
|
<a @click.prevent.stop="open_track_dialog(track)">
|
2023-06-30 21:41:40 +02:00
|
|
|
<mdicon
|
|
|
|
class="icon has-text-dark"
|
|
|
|
name="dots-vertical"
|
|
|
|
size="16"
|
|
|
|
/>
|
2023-06-23 22:23:32 +02:00
|
|
|
</a>
|
|
|
|
</template>
|
2023-07-18 15:19:24 +02:00
|
|
|
</list-item-track-spotify>
|
2023-06-23 22:23:32 +02:00
|
|
|
<VueEternalLoading v-if="offset < total" :load="load_next">
|
|
|
|
<template #no-more> . </template>
|
|
|
|
</VueEternalLoading>
|
2023-07-18 15:19:24 +02:00
|
|
|
<modal-dialog-track-spotify
|
2023-06-23 22:23:32 +02:00
|
|
|
:show="show_track_details_modal"
|
|
|
|
:track="selected_track"
|
|
|
|
:album="selected_track.album"
|
|
|
|
@close="show_track_details_modal = false"
|
|
|
|
/>
|
2023-07-10 15:37:40 +02:00
|
|
|
<modal-dialog-playlist-spotify
|
2023-06-23 22:23:32 +02:00
|
|
|
:show="show_playlist_details_modal"
|
|
|
|
:playlist="playlist"
|
|
|
|
@close="show_playlist_details_modal = false"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</content-with-heading>
|
|
|
|
</div>
|
2018-08-11 07:47:10 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-02-19 06:18:01 +01:00
|
|
|
import ContentWithHeading from '@/templates/ContentWithHeading.vue'
|
2023-07-18 15:19:24 +02:00
|
|
|
import ListItemTrackSpotify from '@/components/ListItemTrackSpotify.vue'
|
2023-07-10 15:37:40 +02:00
|
|
|
import ModalDialogPlaylistSpotify from '@/components/ModalDialogPlaylistSpotify.vue'
|
2023-07-18 15:19:24 +02:00
|
|
|
import ModalDialogTrackSpotify from '@/components/ModalDialogTrackSpotify.vue'
|
2018-08-11 07:47:10 +02:00
|
|
|
import SpotifyWebApi from 'spotify-web-api-js'
|
2023-07-18 14:08:52 +02:00
|
|
|
import store from '@/store'
|
2022-02-19 06:18:01 +01:00
|
|
|
import { VueEternalLoading } from '@ts-pro/vue-eternal-loading'
|
2023-07-18 14:08:52 +02:00
|
|
|
import webapi from '@/webapi'
|
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([
|
2023-07-10 15:37:40 +02:00
|
|
|
spotifyApi.getPlaylist(to.params.id),
|
|
|
|
spotifyApi.getPlaylistTracks(to.params.id, {
|
2022-02-19 06:39:14 +01:00
|
|
|
limit: PAGE_SIZE,
|
2023-06-10 13:46:33 +02:00
|
|
|
offset: 0,
|
|
|
|
market: store.state.spotify.webapi_country
|
2022-02-19 06:39:14 +01:00
|
|
|
})
|
2018-08-11 07:47:10 +02:00
|
|
|
])
|
|
|
|
},
|
|
|
|
|
2023-06-07 21:25:54 +02:00
|
|
|
set(vm, response) {
|
2018-08-11 07:47:10 +02:00
|
|
|
vm.playlist = response[0]
|
|
|
|
vm.tracks = []
|
|
|
|
vm.total = 0
|
|
|
|
vm.offset = 0
|
|
|
|
vm.append_tracks(response[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
2023-07-18 14:08:52 +02:00
|
|
|
name: 'PagePlaylistTracksSpotify',
|
2022-02-19 06:39:14 +01:00
|
|
|
components: {
|
|
|
|
ContentWithHeading,
|
2023-07-18 15:19:24 +02:00
|
|
|
ListItemTrackSpotify,
|
2023-07-10 15:37:40 +02:00
|
|
|
ModalDialogPlaylistSpotify,
|
2023-07-18 15:19:24 +02:00
|
|
|
ModalDialogTrackSpotify,
|
2022-02-19 06:39:14 +01:00
|
|
|
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: {
|
2023-06-07 21:25:54 +02:00
|
|
|
load_next({ 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,
|
2023-06-10 13:46:33 +02:00
|
|
|
offset: this.offset,
|
|
|
|
market: store.state.spotify.webapi_country
|
2022-02-19 06:39:14 +01:00
|
|
|
})
|
|
|
|
.then((data) => {
|
|
|
|
this.append_tracks(data)
|
|
|
|
loaded(data.items.length, PAGE_SIZE)
|
|
|
|
})
|
2018-08-11 07:47:10 +02:00
|
|
|
},
|
|
|
|
|
2023-06-07 21:25:54 +02:00
|
|
|
append_tracks(data) {
|
2023-06-10 18:25:12 +02:00
|
|
|
let position = Math.max(
|
|
|
|
-1,
|
|
|
|
...this.tracks.map((item) => item.position).filter((item) => item)
|
|
|
|
)
|
|
|
|
// Filters out null tracks and adds a position to the playable tracks
|
|
|
|
data.items.forEach((item) => {
|
|
|
|
const track = item.track
|
|
|
|
if (track) {
|
|
|
|
if (track.is_playable) {
|
|
|
|
track.position = ++position
|
|
|
|
}
|
|
|
|
this.tracks.push(track)
|
2023-06-10 13:46:33 +02:00
|
|
|
}
|
2023-06-10 18:25:12 +02:00
|
|
|
})
|
2018-08-11 07:47:10 +02:00
|
|
|
this.total = data.total
|
|
|
|
this.offset += data.limit
|
|
|
|
},
|
|
|
|
|
2023-06-07 21:25:54 +02:00
|
|
|
play() {
|
2018-08-11 07:47:10 +02:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2023-06-07 21:25:54 +02:00
|
|
|
open_track_dialog(track) {
|
2018-12-17 11:52:09 +01:00
|
|
|
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>
|