setup artist discography page

This commit is contained in:
geoffrey45
2022-12-12 13:18:05 +03:00
committed by Mungai Njoroge
parent fd863d188c
commit 35a8446f8b
10 changed files with 189 additions and 45 deletions
+63
View File
@@ -0,0 +1,63 @@
import { defineStore } from "pinia";
import { discographyAlbumTypes } from "@/composables/enums";
import { Album } from "@/interfaces";
import { getArtistAlbums } from "@/composables/fetch/artists";
export default defineStore("artistDiscography", {
state: () => ({
artist: <string>"",
page: discographyAlbumTypes.all,
toShow: <Album[]>[],
albums: <Album[]>[],
eps: <Album[]>[],
singles: <Album[]>[],
appearances: <Album[]>[],
}),
actions: {
setAlbums(page: discographyAlbumTypes) {
switch (page) {
case discographyAlbumTypes.albums:
this.toShow = this.albums;
break;
case discographyAlbumTypes.eps:
this.toShow = this.eps;
break;
case discographyAlbumTypes.singles:
this.toShow = this.singles;
break;
case discographyAlbumTypes.appearances:
this.toShow = this.appearances;
break;
default:
this.toShow = this.albums.concat(
this.eps,
this.singles,
this.appearances
);
}
},
setPage(page: discographyAlbumTypes) {
this.page = page;
},
fetchAlbums(artisthash: string) {
getArtistAlbums(artisthash, true)
.then((data) => {
this.albums = data.albums;
this.eps = data.eps;
this.singles = data.singles;
this.appearances = data.appearances;
})
.then(() => this.setAlbums(this.page));
},
resetAlbums() {
this.albums = [];
this.eps = [];
this.singles = [];
this.appearances = [];
this.toShow = [];
},
},
});