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) 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) { if (!isInitial) {
isRefreshingFavorites.value = true isRefreshingFavorites.value = true
} }
@ -26,22 +37,12 @@ function refreshFavorites({ isInitial = false }) {
favoriteSpotifyPlaylists.value = spotifyPlaylists favoriteSpotifyPlaylists.value = spotifyPlaylists
}) })
.catch(console.error) .catch(console.error)
} else {
favoriteSpotifyPlaylists.value = []
} }
} }
function setAllFavorites(data) { export const useFavorites = () => ({
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, favoriteArtists,
favoriteAlbums, favoriteAlbums,
favoriteSpotifyPlaylists, favoriteSpotifyPlaylists,
@ -49,5 +50,4 @@ export function useFavorites() {
favoriteTracks, favoriteTracks,
isRefreshingFavorites, isRefreshingFavorites,
refreshFavorites refreshFavorites
} })
}