From 3ea5da2d6f9c5820c88d629630ff3cbf40d3d41f Mon Sep 17 00:00:00 2001 From: Sean Russell <60757196+xxxserxxx@users.noreply.github.com> Date: Mon, 28 Oct 2024 02:22:36 -0500 Subject: [PATCH] fix: user interactions in search page with no results resulting in NPE. (#79) --- page_search.go | 62 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/page_search.go b/page_search.go index 2715792..0a01a95 100644 --- a/page_search.go +++ b/page_search.go @@ -92,17 +92,23 @@ func (ui *Ui) createSearchPage() *SearchPage { ui.app.SetFocus(searchPage.albumList) return nil case tcell.KeyEnter: - idx := searchPage.artistList.GetCurrentItem() - searchPage.addArtistToQueue(searchPage.artists[idx]) - return nil + if len(searchPage.artists) != 0 { + idx := searchPage.artistList.GetCurrentItem() + searchPage.addArtistToQueue(searchPage.artists[idx]) + return nil + } + return event } switch event.Rune() { case 'a': - idx := searchPage.artistList.GetCurrentItem() - searchPage.logger.Printf("artistList adding (%d) %s", idx, searchPage.artists[idx].Name) - searchPage.addArtistToQueue(searchPage.artists[idx]) - return nil + if len(searchPage.artists) != 0 { + idx := searchPage.artistList.GetCurrentItem() + searchPage.logger.Printf("artistList adding (%d) %s", idx, searchPage.artists[idx].Name) + searchPage.addArtistToQueue(searchPage.artists[idx]) + return nil + } + return event case '/': searchPage.ui.app.SetFocus(searchPage.searchField) return nil @@ -122,17 +128,23 @@ func (ui *Ui) createSearchPage() *SearchPage { ui.app.SetFocus(searchPage.songList) return nil case tcell.KeyEnter: - idx := searchPage.albumList.GetCurrentItem() - searchPage.addAlbumToQueue(searchPage.albums[idx]) - return nil + if len(searchPage.albums) != 0 { + idx := searchPage.albumList.GetCurrentItem() + searchPage.addAlbumToQueue(searchPage.albums[idx]) + return nil + } + return event } switch event.Rune() { case 'a': - idx := searchPage.albumList.GetCurrentItem() - searchPage.logger.Printf("albumList adding (%d) %s", idx, searchPage.albums[idx].Name) - searchPage.addAlbumToQueue(searchPage.albums[idx]) - return nil + if len(searchPage.albums) != 0 { + idx := searchPage.albumList.GetCurrentItem() + searchPage.logger.Printf("albumList adding (%d) %s", idx, searchPage.albums[idx].Name) + searchPage.addAlbumToQueue(searchPage.albums[idx]) + return nil + } + return event case '/': searchPage.ui.app.SetFocus(searchPage.searchField) return nil @@ -152,18 +164,24 @@ func (ui *Ui) createSearchPage() *SearchPage { ui.app.SetFocus(searchPage.artistList) return nil case tcell.KeyEnter: - idx := searchPage.songList.GetCurrentItem() - ui.addSongToQueue(searchPage.songs[idx]) - ui.queuePage.UpdateQueue() - return nil + if len(searchPage.artists) != 0 { + idx := searchPage.songList.GetCurrentItem() + ui.addSongToQueue(searchPage.songs[idx]) + ui.queuePage.UpdateQueue() + return nil + } + return event } switch event.Rune() { case 'a': - idx := searchPage.songList.GetCurrentItem() - ui.addSongToQueue(searchPage.songs[idx]) - ui.queuePage.updateQueue() - return nil + if len(searchPage.artists) != 0 { + idx := searchPage.songList.GetCurrentItem() + ui.addSongToQueue(searchPage.songs[idx]) + ui.queuePage.updateQueue() + return nil + } + return event case '/': searchPage.ui.app.SetFocus(searchPage.searchField) return nil