mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-07-29 06:02:06 +00:00
sort tracks by tracknumber in album page
This commit is contained in:
parent
22ff52e86e
commit
4b522fd317
@ -7,6 +7,16 @@ import {
|
|||||||
getAlbumBio,
|
getAlbumBio,
|
||||||
} from "../../composables/pages/album";
|
} 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", {
|
export default defineStore("album", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
info: <AlbumInfo>{},
|
info: <AlbumInfo>{},
|
||||||
@ -18,14 +28,13 @@ export default defineStore("album", {
|
|||||||
/**
|
/**
|
||||||
* Fetches a single album information, artists and its tracks from the server
|
* Fetches a single album information, artists and its tracks from the server
|
||||||
* using the title and album-artist of the album.
|
* using the title and album-artist of the album.
|
||||||
* @param title title of the album
|
* @param hash title of the album
|
||||||
* @param albumartist artist of the album
|
|
||||||
*/
|
*/
|
||||||
async fetchTracksAndArtists(hash: string) {
|
async fetchTracksAndArtists(hash: string) {
|
||||||
const tracks = await getAlbumTracks(hash, useNotifStore);
|
const tracks = await getAlbumTracks(hash, useNotifStore);
|
||||||
const artists = await getAlbumArtists(hash);
|
const artists = await getAlbumArtists(hash);
|
||||||
|
|
||||||
this.tracks = tracks.tracks;
|
this.tracks = sortTracks(tracks.tracks);
|
||||||
this.info = tracks.info;
|
this.info = tracks.info;
|
||||||
this.artists = artists;
|
this.artists = artists;
|
||||||
},
|
},
|
||||||
|
@ -30,7 +30,7 @@ const album = useAStore();
|
|||||||
|
|
||||||
onBeforeRouteUpdate(async (to) => {
|
onBeforeRouteUpdate(async (to) => {
|
||||||
await album.fetchTracksAndArtists(to.params.hash.toString());
|
await album.fetchTracksAndArtists(to.params.hash.toString());
|
||||||
album.fetchBio(to.params.album.toString(), to.params.artist.toString());
|
album.fetchBio(to.params.hash.toString());
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user