From c52390117e0c7561dd0688208d7c30d2bf429932 Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Sat, 24 Dec 2022 17:26:03 +0300 Subject: [PATCH] fix playing from album bug when there's inconsistent discs ~ eg. when there's no disc 1, but there's disc 2, or 3 --- src/composables/fetch/album.ts | 1 - src/interfaces.ts | 6 ++++-- src/stores/pages/album.ts | 28 +++++++++++----------------- src/stores/queue.ts | 1 - src/views/AlbumView/Bottom.vue | 24 ------------------------ src/views/AlbumView/index.vue | 6 ++---- 6 files changed, 17 insertions(+), 49 deletions(-) delete mode 100644 src/views/AlbumView/Bottom.vue diff --git a/src/composables/fetch/album.ts b/src/composables/fetch/album.ts index dbcd95e1..a0bf62ea 100644 --- a/src/composables/fetch/album.ts +++ b/src/composables/fetch/album.ts @@ -26,7 +26,6 @@ const getAlbumData = async (hash: string, ToastStore: typeof useNotifStore) => { if (status == 204) { ToastStore().showNotification("Album not created yet!", NotifType.Error); } - return data as AlbumData; }; diff --git a/src/interfaces.ts b/src/interfaces.ts index 38245d99..f18b9cd7 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -16,15 +16,17 @@ export interface Track extends AlbumDisc { filepath?: string; duration?: number; bitrate: number; - genre?: string; image: string; track: number; disc: number; index: number; trackhash: string; - copyright?: string; filetype: string; is_favorite: boolean; + + genre?: string; + copyright?: string; + master_index?: number; } export interface Folder { diff --git a/src/stores/pages/album.ts b/src/stores/pages/album.ts index e6682c51..1fe9ffe6 100644 --- a/src/stores/pages/album.ts +++ b/src/stores/pages/album.ts @@ -9,7 +9,6 @@ import { maxAbumCards } from "@/stores/content-width"; import { getAlbum, getAlbumsFromArtist } from "../../composables/fetch/album"; import { Album, FuseResult, Track } from "../../interfaces"; import { useNotifStore } from "../notification"; -import router from "@/router"; interface Disc { [key: string]: Track[]; @@ -25,12 +24,6 @@ function sortByTrackNumber(tracks: Track[]) { }); } -// function albumHasNoDiscs(album: Album) { -// if (album.is_single) return true; - -// return false; -// } - /** * * @param tracks The raw tracklist from the server @@ -39,8 +32,10 @@ function sortByTrackNumber(tracks: Track[]) { function createDiscs(tracks: Track[]) { return tracks.reduce((group, track) => { const { disc } = track; + group[disc] = group[disc] ?? []; group[disc].push(track); + return group; }, {} as Disc); } @@ -49,7 +44,7 @@ export default defineStore("album", { state: () => ({ query: "", info: {}, - rawTracks: [], + srcTracks: [], albumArtists: <{ artisthash: string; albums: Album[] }[]>[], bio: null, }), @@ -62,8 +57,14 @@ export default defineStore("album", { async fetchTracksAndArtists(hash: string) { const album = await getAlbum(hash, useNotifStore); - this.rawTracks = album.tracks; + this.srcTracks = album.tracks; this.info = album.info; + + this.srcTracks = sortByTrackNumber(this.srcTracks); + + this.srcTracks.forEach((t, index) => { + t.master_index = index; + }); }, async fetchArtistAlbums() { const albumartists = this.info.albumartists; @@ -85,14 +86,7 @@ export default defineStore("album", { }, getters: { discs(): Disc { - return createDiscs(sortByTrackNumber(this.rawTracks)); - }, - allTracks(): Track[] { - return Object.keys(this.discs).reduce((tracks: Track[], disc) => { - const disc_tracks = this.discs[disc]; - - return [...tracks, ...disc_tracks]; - }, []); + return createDiscs(this.srcTracks); }, filteredTracks(): ComputedRef { const discs = this.discs; diff --git a/src/stores/queue.ts b/src/stores/queue.ts index d68e0614..d5b8bd16 100644 --- a/src/stores/queue.ts +++ b/src/stores/queue.ts @@ -46,7 +46,6 @@ export default defineStore("Queue", { play(index: number = 0) { if (this.tracklist.length === 0) return; this.currentindex = index; - console.log(this.tracklist.length); if (!this.mousover) { this.queueScrollFunction(this.currentindex - 1); diff --git a/src/views/AlbumView/Bottom.vue b/src/views/AlbumView/Bottom.vue deleted file mode 100644 index ac9d4113..00000000 --- a/src/views/AlbumView/Bottom.vue +++ /dev/null @@ -1,24 +0,0 @@ - - - - - diff --git a/src/views/AlbumView/index.vue b/src/views/AlbumView/index.vue index d16fcdef..14918e52 100644 --- a/src/views/AlbumView/index.vue +++ b/src/views/AlbumView/index.vue @@ -11,9 +11,7 @@ @@ -122,7 +120,7 @@ const scrollerItems = computed(() => { function playFromAlbum(index: number) { const { title, albumartists, albumhash } = album.info; - queue.playFromAlbum(title, albumhash, album.allTracks); + queue.playFromAlbum(title, albumhash, album.srcTracks); queue.play(index); }