sort tracks by tracknumber in album page

This commit is contained in:
geoffrey45 2022-06-26 19:28:02 +03:00
parent 22ff52e86e
commit 4b522fd317
2 changed files with 13 additions and 4 deletions

View File

@ -7,6 +7,16 @@ import {
getAlbumBio,
} from "../../composables/pages/album";
function sortTracks(tracks: Track[]) {
return tracks.sort((a, b) => {
if (a.tracknumber && b.tracknumber) {
return a.tracknumber - b.tracknumber;
}
return 0;
});
}
export default defineStore("album", {
state: () => ({
info: <AlbumInfo>{},
@ -18,14 +28,13 @@ export default defineStore("album", {
/**
* Fetches a single album information, artists and its tracks from the server
* using the title and album-artist of the album.
* @param title title of the album
* @param albumartist artist of the album
* @param hash title of the album
*/
async fetchTracksAndArtists(hash: string) {
const tracks = await getAlbumTracks(hash, useNotifStore);
const artists = await getAlbumArtists(hash);
this.tracks = tracks.tracks;
this.tracks = sortTracks(tracks.tracks);
this.info = tracks.info;
this.artists = artists;
},

View File

@ -30,7 +30,7 @@ const album = useAStore();
onBeforeRouteUpdate(async (to) => {
await album.fetchTracksAndArtists(to.params.hash.toString());
album.fetchBio(to.params.album.toString(), to.params.artist.toString());
album.fetchBio(to.params.hash.toString());
});
</script>