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>
<h2 style="margin: 0">💜 Favorite albums</h2>
<h2 style="margin: 0">Favorite albums </h2>
</template>
+16 -1
View File
@@ -7,7 +7,7 @@ import { Album, Artist, Track } from "@/interfaces";
export async function addFavorite(favtype: favType, itemhash: string) {
const { data, error } = await useAxios({
url: paths.api.favorite,
url: paths.api.addFavorite,
props: {
type: favtype,
hash: itemhash,
@@ -47,6 +47,21 @@ export async function removeFavorite(favtype: favType, itemhash: string) {
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) {
const { data } = await useAxios({
url: paths.api.favAlbums + `?limit=${limit}`,
+5 -1
View File
@@ -20,11 +20,15 @@ const imageRoutes = {
const paths = {
api: {
album: baseApiUrl + "/album",
favorite: baseApiUrl + "/favorite",
favorites: baseApiUrl + "/favorites",
favAlbums: baseApiUrl + "/albums/favorite",
favTracks: baseApiUrl + "/tracks/favorite",
favArtists: baseApiUrl + "/artists/favorite",
artist: baseApiUrl + "/artist",
favorite: baseApiUrl + "/favorite",
get addFavorite() {
return this.favorite + "/add";
},
get removeFavorite() {
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 FeaturedArtists from "@/components/PlaylistView/ArtistsList.vue";
import { discographyAlbumTypes } from "@/composables/enums";
import {
getFavAlbums,
getFavArtists,
getFavTracks,
} from "@/composables/fetch/favorite";
import { getAllFavs, getFavTracks } from "@/composables/fetch/favorite";
import { Album, Artist, Track } from "@/interfaces";
import useQueueStore from "@/stores/queue";
import { maxAbumCards } from "@/stores/content-width";
@@ -46,11 +42,12 @@ const favTracks: Ref<Track[]> = ref([]);
const favArtists: Ref<Artist[]> = ref([]);
onMounted(() => {
getFavTracks().then((tracks) => (favTracks.value = tracks));
getFavAlbums(maxAbumCards.value).then((albums) => (favAlbums.value = albums));
getFavArtists(maxAbumCards.value).then(
(artists) => (favArtists.value = artists)
);
const max = maxAbumCards.value;
getAllFavs(5, max, max).then((favs) => {
favAlbums.value = favs.albums;
favTracks.value = favs.tracks;
favArtists.value = favs.artists;
});
});
async function handlePlay(index: number) {