join all favorites page request into one

This commit is contained in:
geoffrey45
2023-01-01 21:45:38 +03:00
committed by Mungai Njoroge
parent 22d5f6e896
commit 070dc92733
4 changed files with 29 additions and 13 deletions
@@ -1,3 +1,3 @@
<template> <template>
<h2 style="margin: 0">💜 Favorite albums</h2> <h2 style="margin: 0">Favorite albums </h2>
</template> </template>
+16 -1
View File
@@ -7,7 +7,7 @@ import { Album, Artist, Track } from "@/interfaces";
export async function addFavorite(favtype: favType, itemhash: string) { export async function addFavorite(favtype: favType, itemhash: string) {
const { data, error } = await useAxios({ const { data, error } = await useAxios({
url: paths.api.favorite, url: paths.api.addFavorite,
props: { props: {
type: favtype, type: favtype,
hash: itemhash, hash: itemhash,
@@ -47,6 +47,21 @@ export async function removeFavorite(favtype: favType, itemhash: string) {
return true; return true;
} }
export async function getAllFavs(
track_limit = 6,
album_limit = 6,
artist_limit = 6
) {
const { data } = await useAxios({
url:
paths.api.favorites +
`?track_limit=${track_limit}&album_limit=${album_limit}&artist_limit=${artist_limit}`,
get: true,
});
return data;
}
export async function getFavAlbums(limit = 6) { export async function getFavAlbums(limit = 6) {
const { data } = await useAxios({ const { data } = await useAxios({
url: paths.api.favAlbums + `?limit=${limit}`, url: paths.api.favAlbums + `?limit=${limit}`,
+5 -1
View File
@@ -20,11 +20,15 @@ const imageRoutes = {
const paths = { const paths = {
api: { api: {
album: baseApiUrl + "/album", album: baseApiUrl + "/album",
favorite: baseApiUrl + "/favorite",
favorites: baseApiUrl + "/favorites",
favAlbums: baseApiUrl + "/albums/favorite", favAlbums: baseApiUrl + "/albums/favorite",
favTracks: baseApiUrl + "/tracks/favorite", favTracks: baseApiUrl + "/tracks/favorite",
favArtists: baseApiUrl + "/artists/favorite", favArtists: baseApiUrl + "/artists/favorite",
artist: baseApiUrl + "/artist", artist: baseApiUrl + "/artist",
favorite: baseApiUrl + "/favorite", get addFavorite() {
return this.favorite + "/add";
},
get removeFavorite() { get removeFavorite() {
return this.favorite + "/remove"; return this.favorite + "/remove";
}, },
+7 -10
View File
@@ -30,11 +30,7 @@ import ArtistAlbums from "@/components/AlbumView/ArtistAlbums.vue";
import TopTracks from "@/components/ArtistView/TopTracks.vue"; import TopTracks from "@/components/ArtistView/TopTracks.vue";
import FeaturedArtists from "@/components/PlaylistView/ArtistsList.vue"; import FeaturedArtists from "@/components/PlaylistView/ArtistsList.vue";
import { discographyAlbumTypes } from "@/composables/enums"; import { discographyAlbumTypes } from "@/composables/enums";
import { import { getAllFavs, getFavTracks } from "@/composables/fetch/favorite";
getFavAlbums,
getFavArtists,
getFavTracks,
} from "@/composables/fetch/favorite";
import { Album, Artist, Track } from "@/interfaces"; import { Album, Artist, Track } from "@/interfaces";
import useQueueStore from "@/stores/queue"; import useQueueStore from "@/stores/queue";
import { maxAbumCards } from "@/stores/content-width"; import { maxAbumCards } from "@/stores/content-width";
@@ -46,11 +42,12 @@ const favTracks: Ref<Track[]> = ref([]);
const favArtists: Ref<Artist[]> = ref([]); const favArtists: Ref<Artist[]> = ref([]);
onMounted(() => { onMounted(() => {
getFavTracks().then((tracks) => (favTracks.value = tracks)); const max = maxAbumCards.value;
getFavAlbums(maxAbumCards.value).then((albums) => (favAlbums.value = albums)); getAllFavs(5, max, max).then((favs) => {
getFavArtists(maxAbumCards.value).then( favAlbums.value = favs.albums;
(artists) => (favArtists.value = artists) favTracks.value = favs.tracks;
); favArtists.value = favs.artists;
});
}); });
async function handlePlay(index: number) { async function handlePlay(index: number) {