mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-07-28 13:41:42 +00:00
sort tracks by tracknumber in album page
This commit is contained in:
parent
22ff52e86e
commit
4b522fd317
@ -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;
|
||||
},
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user