fix: favorites and spotify favorites

This commit is contained in:
Roberto Tonino 2021-03-12 21:02:06 +01:00
parent 1e3a4a2212
commit 39a178cfc7
3 changed files with 23 additions and 27 deletions

File diff suppressed because one or more lines are too long

View File

@ -164,7 +164,7 @@
</template>
<script>
import { computed, defineComponent, reactive, toRefs, watch } from '@vue/composition-api'
import { defineComponent, reactive, toRefs, watch } from '@vue/composition-api'
import PreviewControls from '@components/globals/PreviewControls.vue'
import CoverContainer from '@components/globals/CoverContainer.vue'
@ -197,7 +197,8 @@ export default defineComponent({
isRefreshingFavorites,
refreshFavorites
} = useFavorites()
const reloadButton = computed(() => ctx.refs.reloadButton)
refreshFavorites({ isInitial: true })
watch(isRefreshingFavorites, (newVal, oldVal) => {
// If oldVal is true and newOne is false, it means that a refreshing has just terminated

View File

@ -1,7 +1,6 @@
import { ref } from '@vue/composition-api'
import store from '@/store'
import { socket } from '@/utils/socket'
import { fetchData } from '@/utils/api'
const favoriteArtists = ref([])
@ -12,37 +11,21 @@ const favoriteTracks = ref([])
const isRefreshingFavorites = ref(false)
if (store.getters.isLoggedIn) {
refreshFavorites({ isInitial: true })
}
async function refreshFavorites({ isInitial = false }) {
function refreshFavorites({ isInitial = false }) {
if (!isInitial) {
isRefreshingFavorites.value = true
}
const favorites = await fetchData('getUserFavorites')
setAllFavorites(favorites)
fetchData('getUserFavorites').then(setAllFavorites).catch(console.error)
if (store.getters.isLoggedWithSpotify) {
// TODO
const spotifyPlaylists = await fetchData('getUserSpotifyPlaylists', {
fetchData('getUserSpotifyPlaylists', {
spotifyUser: store.getters.getSpotifyUser.id
})
favoriteSpotifyPlaylists.value = spotifyPlaylists
}
}
export function useFavorites() {
return {
favoriteArtists,
favoriteAlbums,
favoriteSpotifyPlaylists,
favoritePlaylists,
favoriteTracks,
isRefreshingFavorites,
refreshFavorites
.then(({ data: spotifyPlaylists }) => {
favoriteSpotifyPlaylists.value = spotifyPlaylists
})
.catch(console.error)
}
}
@ -56,3 +39,15 @@ function setAllFavorites(data) {
favoritePlaylists.value = playlists
favoriteTracks.value = tracks
}
export function useFavorites() {
return {
favoriteArtists,
favoriteAlbums,
favoriteSpotifyPlaylists,
favoritePlaylists,
favoriteTracks,
isRefreshingFavorites,
refreshFavorites
}
}