fixed search/songs
Signed-off-by: mbrucedogs <mbrucedogs@gmail.com>
This commit is contained in:
parent
d2f2eebc7d
commit
7d2369252e
@ -70,17 +70,16 @@ export const sortTopPlayedByCount = (songs: TopPlayed[]): TopPlayed[] => {
|
|||||||
// Sort songs by artist then title (case insensitive)
|
// Sort songs by artist then title (case insensitive)
|
||||||
export const sortSongsByArtistAndTitle = (songs: Song[]): Song[] => {
|
export const sortSongsByArtistAndTitle = (songs: Song[]): Song[] => {
|
||||||
const sortedSongs = [...songs].sort((a, b) => {
|
const sortedSongs = [...songs].sort((a, b) => {
|
||||||
// First sort by artist (case insensitive)
|
// Defensive: treat missing artist/title as empty string
|
||||||
const artistA = a.artist.toLowerCase();
|
const artistA = (a.artist || '').toLowerCase();
|
||||||
const artistB = b.artist.toLowerCase();
|
const artistB = (b.artist || '').toLowerCase();
|
||||||
|
|
||||||
if (artistA !== artistB) {
|
if (artistA !== artistB) {
|
||||||
return artistA.localeCompare(artistB);
|
return artistA.localeCompare(artistB);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If artists are the same, sort by title (case insensitive)
|
const titleA = (a.title || '').toLowerCase();
|
||||||
const titleA = a.title.toLowerCase();
|
const titleB = (b.title || '').toLowerCase();
|
||||||
const titleB = b.title.toLowerCase();
|
|
||||||
return titleA.localeCompare(titleB);
|
return titleA.localeCompare(titleB);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user