fix: correctly resetting favorites according to spotify login status

This commit is contained in:
Roberto Tonino 2021-08-11 11:47:45 +02:00
parent 6feb972bc6
commit 5f5301b6b8

View file

@ -11,7 +11,18 @@ const favoriteTracks = ref([])
const isRefreshingFavorites = ref(false)
function refreshFavorites({ isInitial = false }) {
const setAllFavorites = data => {
const { tracks, albums, artists, playlists } = data
isRefreshingFavorites.value = false
favoriteArtists.value = artists
favoriteAlbums.value = albums
favoritePlaylists.value = playlists
favoriteTracks.value = tracks
}
const refreshFavorites = ({ isInitial = false }) => {
if (!isInitial) {
isRefreshingFavorites.value = true
}
@ -26,28 +37,17 @@ function refreshFavorites({ isInitial = false }) {
favoriteSpotifyPlaylists.value = spotifyPlaylists
})
.catch(console.error)
} else {
favoriteSpotifyPlaylists.value = []
}
}
function setAllFavorites(data) {
const { tracks, albums, artists, playlists } = data
isRefreshingFavorites.value = false
favoriteArtists.value = artists
favoriteAlbums.value = albums
favoritePlaylists.value = playlists
favoriteTracks.value = tracks
}
export function useFavorites() {
return {
favoriteArtists,
favoriteAlbums,
favoriteSpotifyPlaylists,
favoritePlaylists,
favoriteTracks,
isRefreshingFavorites,
refreshFavorites
}
}
export const useFavorites = () => ({
favoriteArtists,
favoriteAlbums,
favoriteSpotifyPlaylists,
favoritePlaylists,
favoriteTracks,
isRefreshingFavorites,
refreshFavorites
})