owntone-server/web-src/src/pages/PageMusicSpotifyNewReleases.vue

62 lines
1.3 KiB
Vue
Raw Normal View History

<template>
2022-02-19 06:18:01 +01:00
<div class="fd-page-with-tabs">
<tabs-music />
<content-with-heading>
<template #heading-left>
<p class="title is-4" v-text="$t('page.spotify.music.new-releases')" />
</template>
<template #content>
<list-albums-spotify :items="new_releases" />
</template>
</content-with-heading>
</div>
</template>
<script>
2022-02-19 06:18:01 +01:00
import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ListAlbumsSpotify from '@/components/ListAlbumsSpotify.vue'
import SpotifyWebApi from 'spotify-web-api-js'
import TabsMusic from '@/components/TabsMusic.vue'
import webapi from '@/webapi'
2022-02-19 06:18:01 +01:00
const dataObject = {
load(to) {
return webapi.spotify().then(({ data }) => {
const spotifyApi = new SpotifyWebApi()
spotifyApi.setAccessToken(data.webapi_token)
return spotifyApi.getNewReleases({
country: data.webapi_country,
limit: 50
})
})
},
set(vm, response) {
vm.new_releases = response.albums.items
}
}
export default {
name: 'PageMusicSpotifyNewReleases',
components: {
ContentWithHeading,
ListAlbumsSpotify,
TabsMusic
},
beforeRouteEnter(to, from, next) {
dataObject.load(to).then((response) => {
next((vm) => dataObject.set(vm, response))
})
},
data() {
return {
new_releases: []
}
}
}
</script>
<style></style>