From 9c5b763267ee1062bea5760475a249a8b59b32c2 Mon Sep 17 00:00:00 2001 From: Phan An Date: Tue, 15 Oct 2024 22:46:03 +0700 Subject: [PATCH] fix: sort by disc/track not working if only one disc (#1854) --- .../assets/js/composables/useSongList.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/resources/assets/js/composables/useSongList.ts b/resources/assets/js/composables/useSongList.ts index a71f5987..d8883636 100644 --- a/resources/assets/js/composables/useSongList.ts +++ b/resources/assets/js/composables/useSongList.ts @@ -135,9 +135,22 @@ export const useSongList = ( return playables.value } - return sortField.value - ? orderBy(fuzzy.search(filterKeywords.value), extendedSortFields.value!, sortOrder.value) - : fuzzy.search(filterKeywords.value) + const filtered = fuzzy.search(filterKeywords.value) + + if (!sortField.value) { + return filtered + } + + const sortFields = extendedSortFields.value! + + if (sortFields[0] === 'disc' && sortFields.length > 1 && new Set(filtered.map(p => p.disc ?? null)).size === 1) { + // If we're sorting by disc and there's only one disc, we remove disc from the sort fields. + // Otherwise, the tracks will be sorted by disc number first, and since there's only one disc, + // the track order will remain the same through alternating between asc and desc. + sortFields.shift() + } + + return orderBy(filtered, sortFields, sortOrder.value) }) const onPressEnter = async (event: KeyboardEvent) => {