fix: favorites fetching

This commit is contained in:
Roberto Tonino 2021-03-12 20:12:46 +01:00
parent 236bfbb77e
commit b2b85fb84e
3 changed files with 22 additions and 70 deletions

View File

@ -12240,7 +12240,9 @@ function fetchData(key, data = {}) {
url.searchParams.append(key, data[key]); url.searchParams.append(key, data[key]);
}); });
return fetch(url.href).then(response => response.json()) return fetch(url.href)
.then(response => response.json())
.catch(() => {})
} }
function sendToServer(key, data) { function sendToServer(key, data) {
@ -36285,14 +36287,17 @@ async function refreshFavorites({ isInitial = false }) {
isRefreshingFavorites.value = true; isRefreshingFavorites.value = true;
} }
const favorites = await fetchData('getFavorites'); const favorites = await fetchData('getUserFavorites');
setAllFavorites(favorites); setAllFavorites(favorites);
if (store.getters.isLoggedWithSpotify) { if (store.getters.isLoggedWithSpotify) {
// TODO // TODO
const res = await fetchData('getUserSpotifyPlaylists', { spotifyUser: store.getters.getSpotifyUser.id }); const spotifyPlaylists = await fetchData('getUserSpotifyPlaylists', {
// socket.emit('update_userSpotifyPlaylists', store.getters.getSpotifyUser.id) spotifyUser: store.getters.getSpotifyUser.id
});
console.log({ spotifyPlaylists });
favoriteSpotifyPlaylists.value = spotifyPlaylists;
} }
} }
@ -36311,43 +36316,14 @@ function useFavorites() {
function setAllFavorites(data) { function setAllFavorites(data) {
const { tracks, albums, artists, playlists } = data; const { tracks, albums, artists, playlists } = data;
isRefreshingFavorites.value = false;
favoriteArtists.value = artists; favoriteArtists.value = artists;
favoriteAlbums.value = albums; favoriteAlbums.value = albums;
favoritePlaylists.value = playlists; favoritePlaylists.value = playlists;
favoriteTracks.value = tracks; favoriteTracks.value = tracks;
} }
socket.on('updated_userFavorites', data => {
setAllFavorites(data);
// Commented out because the corresponding emit function is never called at the moment
// therefore isRefreshingFavorites is never set to true
// isRefreshingFavorites.value = false
});
socket.on('init_favorites', data => {
setAllFavorites(data);
isRefreshingFavorites.value = false;
});
socket.on('updated_userSpotifyPlaylists', data => {
favoriteSpotifyPlaylists.value = data;
});
socket.on('updated_userSpotifyPlaylists', data => {
favoriteSpotifyPlaylists.value = data;
});
socket.on('updated_userPlaylists', data => {
favoritePlaylists.value = data;
});
socket.on('updated_userAlbums', data => {
favoriteAlbums.value = data;
});
socket.on('updated_userArtist', data => {
favoriteArtists.value = data;
});
socket.on('updated_userTracks', data => {
favoriteTracks.value = data;
});
// //
var script$g = defineComponent({ var script$g = defineComponent({

View File

@ -21,14 +21,17 @@ async function refreshFavorites({ isInitial = false }) {
isRefreshingFavorites.value = true isRefreshingFavorites.value = true
} }
const favorites = await fetchData('getFavorites') const favorites = await fetchData('getUserFavorites')
setAllFavorites(favorites) setAllFavorites(favorites)
if (store.getters.isLoggedWithSpotify) { if (store.getters.isLoggedWithSpotify) {
// TODO // TODO
const res = await fetchData('getUserSpotifyPlaylists', { spotifyUser: store.getters.getSpotifyUser.id }) const spotifyPlaylists = await fetchData('getUserSpotifyPlaylists', {
// socket.emit('update_userSpotifyPlaylists', store.getters.getSpotifyUser.id) spotifyUser: store.getters.getSpotifyUser.id
})
console.log({ spotifyPlaylists })
favoriteSpotifyPlaylists.value = spotifyPlaylists
} }
} }
@ -47,39 +50,10 @@ export function useFavorites() {
function setAllFavorites(data) { function setAllFavorites(data) {
const { tracks, albums, artists, playlists } = data const { tracks, albums, artists, playlists } = data
isRefreshingFavorites.value = false
favoriteArtists.value = artists favoriteArtists.value = artists
favoriteAlbums.value = albums favoriteAlbums.value = albums
favoritePlaylists.value = playlists favoritePlaylists.value = playlists
favoriteTracks.value = tracks favoriteTracks.value = tracks
} }
socket.on('updated_userFavorites', data => {
setAllFavorites(data)
// Commented out because the corresponding emit function is never called at the moment
// therefore isRefreshingFavorites is never set to true
// isRefreshingFavorites.value = false
})
socket.on('init_favorites', data => {
setAllFavorites(data)
isRefreshingFavorites.value = false
})
socket.on('updated_userSpotifyPlaylists', data => {
favoriteSpotifyPlaylists.value = data
})
socket.on('updated_userSpotifyPlaylists', data => {
favoriteSpotifyPlaylists.value = data
})
socket.on('updated_userPlaylists', data => {
favoritePlaylists.value = data
})
socket.on('updated_userAlbums', data => {
favoriteAlbums.value = data
})
socket.on('updated_userArtist', data => {
favoriteArtists.value = data
})
socket.on('updated_userTracks', data => {
favoriteTracks.value = data
})

View File

@ -5,7 +5,9 @@ export function fetchData(key, data = {}) {
url.searchParams.append(key, data[key]) url.searchParams.append(key, data[key])
}) })
return fetch(url.href).then(response => response.json()) return fetch(url.href)
.then(response => response.json())
.catch(() => {})
} }
export function sendToServer(key, data) { export function sendToServer(key, data) {