fix: favorites and spotify favorites
This commit is contained in:
parent
1e3a4a2212
commit
39a178cfc7
File diff suppressed because one or more lines are too long
@ -164,7 +164,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<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 PreviewControls from '@components/globals/PreviewControls.vue'
|
||||||
import CoverContainer from '@components/globals/CoverContainer.vue'
|
import CoverContainer from '@components/globals/CoverContainer.vue'
|
||||||
@ -197,7 +197,8 @@ export default defineComponent({
|
|||||||
isRefreshingFavorites,
|
isRefreshingFavorites,
|
||||||
refreshFavorites
|
refreshFavorites
|
||||||
} = useFavorites()
|
} = useFavorites()
|
||||||
const reloadButton = computed(() => ctx.refs.reloadButton)
|
|
||||||
|
refreshFavorites({ isInitial: true })
|
||||||
|
|
||||||
watch(isRefreshingFavorites, (newVal, oldVal) => {
|
watch(isRefreshingFavorites, (newVal, oldVal) => {
|
||||||
// If oldVal is true and newOne is false, it means that a refreshing has just terminated
|
// If oldVal is true and newOne is false, it means that a refreshing has just terminated
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { ref } from '@vue/composition-api'
|
import { ref } from '@vue/composition-api'
|
||||||
|
|
||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
import { socket } from '@/utils/socket'
|
|
||||||
import { fetchData } from '@/utils/api'
|
import { fetchData } from '@/utils/api'
|
||||||
|
|
||||||
const favoriteArtists = ref([])
|
const favoriteArtists = ref([])
|
||||||
@ -12,37 +11,21 @@ const favoriteTracks = ref([])
|
|||||||
|
|
||||||
const isRefreshingFavorites = ref(false)
|
const isRefreshingFavorites = ref(false)
|
||||||
|
|
||||||
if (store.getters.isLoggedIn) {
|
function refreshFavorites({ isInitial = false }) {
|
||||||
refreshFavorites({ isInitial: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
async function refreshFavorites({ isInitial = false }) {
|
|
||||||
if (!isInitial) {
|
if (!isInitial) {
|
||||||
isRefreshingFavorites.value = true
|
isRefreshingFavorites.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const favorites = await fetchData('getUserFavorites')
|
fetchData('getUserFavorites').then(setAllFavorites).catch(console.error)
|
||||||
|
|
||||||
setAllFavorites(favorites)
|
|
||||||
|
|
||||||
if (store.getters.isLoggedWithSpotify) {
|
if (store.getters.isLoggedWithSpotify) {
|
||||||
// TODO
|
fetchData('getUserSpotifyPlaylists', {
|
||||||
const spotifyPlaylists = await fetchData('getUserSpotifyPlaylists', {
|
|
||||||
spotifyUser: store.getters.getSpotifyUser.id
|
spotifyUser: store.getters.getSpotifyUser.id
|
||||||
})
|
})
|
||||||
|
.then(({ data: spotifyPlaylists }) => {
|
||||||
favoriteSpotifyPlaylists.value = spotifyPlaylists
|
favoriteSpotifyPlaylists.value = spotifyPlaylists
|
||||||
}
|
})
|
||||||
}
|
.catch(console.error)
|
||||||
|
|
||||||
export function useFavorites() {
|
|
||||||
return {
|
|
||||||
favoriteArtists,
|
|
||||||
favoriteAlbums,
|
|
||||||
favoriteSpotifyPlaylists,
|
|
||||||
favoritePlaylists,
|
|
||||||
favoriteTracks,
|
|
||||||
isRefreshingFavorites,
|
|
||||||
refreshFavorites
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,3 +39,15 @@ function setAllFavorites(data) {
|
|||||||
favoritePlaylists.value = playlists
|
favoritePlaylists.value = playlists
|
||||||
favoriteTracks.value = tracks
|
favoriteTracks.value = tracks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useFavorites() {
|
||||||
|
return {
|
||||||
|
favoriteArtists,
|
||||||
|
favoriteAlbums,
|
||||||
|
favoriteSpotifyPlaylists,
|
||||||
|
favoritePlaylists,
|
||||||
|
favoriteTracks,
|
||||||
|
isRefreshingFavorites,
|
||||||
|
refreshFavorites
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user