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

74 lines
1.7 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-item-album-spotify :items="new_releases" />
</template>
</content-with-heading>
</div>
</template>
<script>
import * as types from '@/store/mutation_types'
2022-02-19 06:18:01 +01:00
import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ListItemAlbumSpotify from '@/components/ListItemAlbumSpotify.vue'
import SpotifyWebApi from 'spotify-web-api-js'
import TabsMusic from '@/components/TabsMusic.vue'
2024-02-28 15:24:55 +01:00
import store from '@/store'
2022-02-19 06:18:01 +01:00
const dataObject = {
load(to) {
if (store.state.spotify_new_releases.length > 0) {
return Promise.resolve()
}
const spotifyApi = new SpotifyWebApi()
spotifyApi.setAccessToken(store.state.spotify.webapi_token)
return spotifyApi.getNewReleases({
country: store.state.spotify.webapi_country,
limit: 50
})
},
set(vm, response) {
if (response) {
store.commit(types.SPOTIFY_NEW_RELEASES, response.albums.items)
}
}
}
export default {
name: 'PageMusicSpotifyNewReleases',
components: {
ContentWithHeading,
ListItemAlbumSpotify,
TabsMusic
},
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()
})
},
computed: {
2024-03-24 18:05:29 +01:00
new_releases() {
return this.$store.state.spotify_new_releases
}
}
}
</script>
<style></style>