fix: sort by disc/track not working if only one disc (#1854)

This commit is contained in:
Phan An 2024-10-15 22:46:03 +07:00 committed by GitHub
parent abfa65bfe8
commit 9c5b763267
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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) => {