fixed search/songs

Signed-off-by: mbrucedogs <mbrucedogs@gmail.com>
This commit is contained in:
mbrucedogs 2025-07-21 12:23:51 -05:00
parent d2f2eebc7d
commit 7d2369252e

View File

@ -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);
}); });