[web] Fix a bug preventing the "featured playlists" and "new releases" pages to work after a page refresh

This commit is contained in:
Alain Nussbaumer 2024-04-01 20:42:05 +02:00
parent 72b30aabf9
commit 839e475c3e
5 changed files with 45 additions and 81 deletions

View File

@ -48,45 +48,34 @@
</template> </template>
<script> <script>
import * as types from '@/store/mutation_types'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ListAlbumsSpotify from '@/components/ListAlbumsSpotify.vue' import ListAlbumsSpotify from '@/components/ListAlbumsSpotify.vue'
import ListPlaylistsSpotify from '@/components/ListPlaylistsSpotify.vue' import ListPlaylistsSpotify from '@/components/ListPlaylistsSpotify.vue'
import SpotifyWebApi from 'spotify-web-api-js' import SpotifyWebApi from 'spotify-web-api-js'
import TabsMusic from '@/components/TabsMusic.vue' import TabsMusic from '@/components/TabsMusic.vue'
import store from '@/store' import webapi from '@/webapi'
const dataObject = { const dataObject = {
load(to) { load(to) {
if ( return webapi.spotify().then(({ data }) => {
store.state.spotify_new_releases.length > 0 && const spotifyApi = new SpotifyWebApi()
store.state.spotify_featured_playlists.length > 0 spotifyApi.setAccessToken(data.webapi_token)
) { return Promise.all([
return Promise.resolve() spotifyApi.getNewReleases({
} country: data.webapi_country,
limit: 3
const spotifyApi = new SpotifyWebApi() }),
spotifyApi.setAccessToken(store.state.spotify.webapi_token) spotifyApi.getFeaturedPlaylists({
return Promise.all([ country: data.webapi_country,
spotifyApi.getNewReleases({ limit: 3
country: store.state.spotify.webapi_country, })
limit: 50 ])
}), })
spotifyApi.getFeaturedPlaylists({
country: store.state.spotify.webapi_country,
limit: 50
})
])
}, },
set(vm, response) { set(vm, response) {
if (response) { vm.new_releases = response[0].albums.items
store.commit(types.SPOTIFY_NEW_RELEASES, response[0].albums.items) vm.featured_playlists = response[1].playlists.items
store.commit(
types.SPOTIFY_FEATURED_PLAYLISTS,
response[1].playlists.items
)
}
} }
} }
@ -105,12 +94,10 @@ export default {
}) })
}, },
computed: { data() {
featured_playlists() { return {
return this.$store.state.spotify_featured_playlists.slice(0, 3) featured_playlists: [],
}, new_releases: []
new_releases() {
return this.$store.state.spotify_new_releases.slice(0, 3)
} }
} }
} }

View File

@ -16,31 +16,26 @@
</template> </template>
<script> <script>
import * as types from '@/store/mutation_types'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ListPlaylistsSpotify from '@/components/ListPlaylistsSpotify.vue' import ListPlaylistsSpotify from '@/components/ListPlaylistsSpotify.vue'
import SpotifyWebApi from 'spotify-web-api-js' import SpotifyWebApi from 'spotify-web-api-js'
import TabsMusic from '@/components/TabsMusic.vue' import TabsMusic from '@/components/TabsMusic.vue'
import store from '@/store' import webapi from '@/webapi'
const dataObject = { const dataObject = {
load(to) { load(to) {
if (store.state.spotify_featured_playlists.length > 0) { return webapi.spotify().then(({ data }) => {
return Promise.resolve() const spotifyApi = new SpotifyWebApi()
} spotifyApi.setAccessToken(data.webapi_token)
return spotifyApi.getFeaturedPlaylists({
const spotifyApi = new SpotifyWebApi() country: data.webapi_country,
spotifyApi.setAccessToken(store.state.spotify.webapi_token) limit: 50
spotifyApi.getFeaturedPlaylists({ })
country: store.state.spotify.webapi_country,
limit: 50
}) })
}, },
set(vm, response) { set(vm, response) {
if (response) { vm.featured_playlists = response.playlists.items
store.commit(types.SPOTIFY_FEATURED_PLAYLISTS, response.playlists.items)
}
} }
} }
@ -58,9 +53,9 @@ export default {
}) })
}, },
computed: { data() {
featured_playlists() { return {
return this.$store.state.spotify_featured_playlists featured_playlists: []
} }
} }
} }

View File

@ -13,31 +13,26 @@
</template> </template>
<script> <script>
import * as types from '@/store/mutation_types'
import ContentWithHeading from '@/templates/ContentWithHeading.vue' import ContentWithHeading from '@/templates/ContentWithHeading.vue'
import ListAlbumsSpotify from '@/components/ListAlbumsSpotify.vue' import ListAlbumsSpotify from '@/components/ListAlbumsSpotify.vue'
import SpotifyWebApi from 'spotify-web-api-js' import SpotifyWebApi from 'spotify-web-api-js'
import TabsMusic from '@/components/TabsMusic.vue' import TabsMusic from '@/components/TabsMusic.vue'
import store from '@/store' import webapi from '@/webapi'
const dataObject = { const dataObject = {
load(to) { load(to) {
if (store.state.spotify_new_releases.length > 0) { return webapi.spotify().then(({ data }) => {
return Promise.resolve() const spotifyApi = new SpotifyWebApi()
} spotifyApi.setAccessToken(data.webapi_token)
return spotifyApi.getNewReleases({
const spotifyApi = new SpotifyWebApi() country: data.webapi_country,
spotifyApi.setAccessToken(store.state.spotify.webapi_token) limit: 50
return spotifyApi.getNewReleases({ })
country: store.state.spotify.webapi_country,
limit: 50
}) })
}, },
set(vm, response) { set(vm, response) {
if (response) { vm.new_releases = response.albums.items
store.commit(types.SPOTIFY_NEW_RELEASES, response.albums.items)
}
} }
} }
@ -55,9 +50,9 @@ export default {
}) })
}, },
computed: { data() {
new_releases() { return {
return this.$store.state.spotify_new_releases new_releases: []
} }
} }
} }

View File

@ -63,8 +63,6 @@ export default createStore({
show_player_menu: false, show_player_menu: false,
show_update_dialog: false, show_update_dialog: false,
spotify: {}, spotify: {},
spotify_featured_playlists: [],
spotify_new_releases: [],
update_dialog_scan_kind: '' update_dialog_scan_kind: ''
} }
}, },
@ -132,12 +130,6 @@ export default createStore({
[types.UPDATE_PAIRING](state, pairing) { [types.UPDATE_PAIRING](state, pairing) {
state.pairing = pairing state.pairing = pairing
}, },
[types.SPOTIFY_NEW_RELEASES](state, newReleases) {
state.spotify_new_releases = newReleases
},
[types.SPOTIFY_FEATURED_PLAYLISTS](state, featuredPlaylists) {
state.spotify_featured_playlists = featuredPlaylists
},
[types.SEARCH_SOURCE](state, searchSource) { [types.SEARCH_SOURCE](state, searchSource) {
state.search_source = searchSource state.search_source = searchSource
}, },

View File

@ -9,12 +9,7 @@ export const UPDATE_LYRICS = 'UPDATE_LYRICS'
export const UPDATE_LASTFM = 'UPDATE_LASTFM' export const UPDATE_LASTFM = 'UPDATE_LASTFM'
export const UPDATE_SPOTIFY = 'UPDATE_SPOTIFY' export const UPDATE_SPOTIFY = 'UPDATE_SPOTIFY'
export const UPDATE_PAIRING = 'UPDATE_PAIRING' export const UPDATE_PAIRING = 'UPDATE_PAIRING'
export const SPOTIFY_NEW_RELEASES = 'SPOTIFY_NEW_RELEASES'
export const SPOTIFY_FEATURED_PLAYLISTS = 'SPOTIFY_FEATURED_PLAYLISTS'
export const SEARCH_SOURCE = 'SEARCH_SOURCE' export const SEARCH_SOURCE = 'SEARCH_SOURCE'
export const COMPOSER_TRACKS_SORT = 'COMPOSER_TRACKS_SORT' export const COMPOSER_TRACKS_SORT = 'COMPOSER_TRACKS_SORT'
export const GENRE_TRACKS_SORT = 'GENRE_TRACKS_SORT' export const GENRE_TRACKS_SORT = 'GENRE_TRACKS_SORT'
export const HIDE_SINGLES = 'HIDE_SINGLES' export const HIDE_SINGLES = 'HIDE_SINGLES'