Skip to content

Commit

Permalink
fix: search item adding regressions
Browse files Browse the repository at this point in the history
fix: search page focus improvements
  • Loading branch information
xxxserxxx committed Jan 9, 2025
1 parent d69b670 commit 2cc455f
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 29 deletions.
1 change: 1 addition & 0 deletions event_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (ui *Ui) guiEventLoop() {
}

ui.app.QueueUpdateDraw(func() {
// FIXME (A) scanning is not showing scanning anymore
txt := formatPlayerStatus(ui.scanning, statusData.Volume, statusData.Position, statusData.Duration)
ui.playerStatus.SetText(txt)
if ui.queuePage.lyrics != nil {
Expand Down
2 changes: 1 addition & 1 deletion gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/spezifisch/stmps/subsonic"
)

// struct contains all the updatable elements of the Ui
// TODO (B) Put all "heavy" structures behind a Queue
// TODO (B) Don't let connection calls hang up the UI
// struct contains all the updatable elements of the Ui
type Ui struct {
app *tview.Application
pages *tview.Pages
Expand Down
3 changes: 3 additions & 0 deletions gui_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ func (ui *Ui) ShowPage(name string) {
ui.menuWidget.SetActivePage(name)
_, prim := ui.pages.GetFrontPage()
ui.app.SetFocus(prim)
if name == PageSearch {
ui.searchPage.aproposFocus()
}
}

func (ui *Ui) Quit() {
Expand Down
3 changes: 1 addition & 2 deletions lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

package main

// TODO (A) document combining Cache with LRU; is a combining wrapper needed?

// LRU is a least-recently-used algorithm for Caches. It tracks the age of items in
// a Cache by access time, and when the cache size is greater than a configured value,
// reports which items in excess of the cache size are the least recently used.
// TODO (A) document combining Cache with LRU; is a combining wrapper needed?
type LRU struct {
lookup map[string]*node
head *node
Expand Down
1 change: 1 addition & 0 deletions page_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type QueuePage struct {
lyrics *tview.TextView
coverArt *tview.Image

// FIXME (A) make *sure* that lyrics are being cleared between songs
currentLyrics subsonic.StructuredLyrics

// external refs
Expand Down
76 changes: 52 additions & 24 deletions page_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,17 @@ func (ui *Ui) createSearchPage() *SearchPage {

switch event.Rune() {
case 'a':
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
idx := searchPage.artistList.GetCurrentItem()
if idx >= 0 && searchPage.artistList.GetItemCount() > 0 {
if idx < len(searchPage.artists) {
searchPage.addArtistToQueue(searchPage.artists[idx])
idx++
if idx < searchPage.artistList.GetItemCount() {
searchPage.artistList.SetCurrentItem(idx)
}
return nil
}
searchPage.logger.Printf("error: searchPage.artistList event selected index %d > %d artists, which shouldn't be possible", idx, len(searchPage.artists))
}
return event
case '/':
Expand Down Expand Up @@ -166,20 +172,33 @@ func (ui *Ui) createSearchPage() *SearchPage {

switch event.Rune() {
case 'a':
idx := searchPage.albumList.GetCurrentItem()
if idx < 0 || searchPage.albumList.GetItemCount() == 0 {
return event
}

if searchPage.queryGenre {
idx := searchPage.albumList.GetCurrentItem()
if idx < searchPage.albumList.GetItemCount() {
genre, _ := searchPage.albumList.GetItemText(idx)
searchPage.addGenreToQueue(genre)
// Handle the search-by-genre case
if idx >= searchPage.albumList.GetItemCount() {
searchPage.logger.Printf("error: searchPage.albumList event selected index %d > %d genres, which shouldn't be possible", idx, searchPage.albumList.GetItemCount())
return event
}
genre, _ := searchPage.albumList.GetItemText(idx)
searchPage.addGenreToQueue(genre)
} else {
// Handle the search-by-match case
if idx >= len(searchPage.albums) {
searchPage.logger.Printf("error: searchPage.albumList event selected index %d > %d albums, which shouldn't be possible", idx, len(searchPage.albums))
return event
}
return nil
}
idx := searchPage.albumList.GetCurrentItem()
if idx >= 0 && idx < len(searchPage.albums) {
searchPage.addAlbumToQueue(searchPage.albums[idx])
return nil
}
return event

idx++
if idx < searchPage.albumList.GetItemCount() {
searchPage.albumList.SetCurrentItem(idx)
}
return nil
case '/':
searchPage.ui.app.SetFocus(searchPage.searchField)
return nil
Expand Down Expand Up @@ -220,11 +239,18 @@ func (ui *Ui) createSearchPage() *SearchPage {

switch event.Rune() {
case 'a':
if len(searchPage.artists) != 0 {
idx := searchPage.songList.GetCurrentItem()
ui.addSongToQueue(searchPage.songs[idx])
ui.queuePage.updateQueue()
return nil
idx := searchPage.songList.GetCurrentItem()
if idx >= 0 && searchPage.songList.GetItemCount() > 0 {
if idx < len(searchPage.songs) {
ui.addSongToQueue(searchPage.songs[idx])
idx++
if idx < searchPage.songList.GetItemCount() {
searchPage.songList.SetCurrentItem(idx)
}
ui.queuePage.updateQueue()
return nil
}
searchPage.logger.Printf("error: searchPage.songList event selected index %d > %d songs, which shouldn't be possible", idx, len(searchPage.songs))
}
return event
case '/':
Expand Down Expand Up @@ -367,6 +393,8 @@ func (s *SearchPage) search(search chan string) {
}
}

// addGenreToQueue adds all songs tagged with the genre, by genre name, to the queue.
// The genre name is e.g. "Rock", "folk", "acid rock", etc.
func (s *SearchPage) addGenreToQueue(query string) {
var songOff int
for {
Expand Down Expand Up @@ -441,15 +469,15 @@ func (s *SearchPage) addAlbumToQueue(entity subsonic.Ider) {
}

func (s *SearchPage) aproposFocus() {
if s.queryGenre {
if s.queryGenre && s.songList.GetItemCount() > 0 {
s.ui.app.SetFocus(s.songList)
return
}
if len(s.artists) != 0 {
if s.artistList.GetItemCount() != 0 {
s.ui.app.SetFocus(s.artistList)
} else if len(s.albums) != 0 {
} else if s.albumList.GetItemCount() != 0 {
s.ui.app.SetFocus(s.albumList)
} else if len(s.songs) != 0 {
} else if s.songList.GetItemCount() != 0 {
s.ui.app.SetFocus(s.songList)
} else {
s.ui.app.SetFocus(s.artistList)
Expand Down
1 change: 0 additions & 1 deletion stmps.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
// TODO (D) Update screenshots in the README
// TODO (A) Add mocking library
// TODO (C) Get unit tests up to some non-embarassing percentage
// TODO (B) Merge feature_27_save_queue / issue-54-save-queue-on-exit / seekable-queue-load, and finish the restoring play location on first run, or hotkey
// TODO (C) Support "Download" for songs, albums, artists, and playlists

var osExit = os.Exit // A variable to allow mocking os.Exit in tests
Expand Down
2 changes: 1 addition & 1 deletion subsonic/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func (connection *Connection) GetIndexes() (Indexes, error) {

// GetIndexes returns an indexed structure of all artists
// Artists in the response are _not_ sorted
// TODO (B) Artists that only exist under Various Artists don't show up as their own artists in getArtists calls to either gonic or Navidrome. E.g. if an artist has a single song tagged with artist=X and albumartist=A, living in directory A/somealbum/song.opus, that artist will not appear in getArtists
// https://opensubsonic.netlify.app/docs/endpoints/getartists/
// TODO (B) Artists that only exist under Various Artists don't show up as their own artists in getArtists calls to either gonic or Navidrome. E.g. if an artist has a single song tagged with artist=X and albumartist=A, living in directory A/somealbum/song.opus, that artist will not appear in getArtists
func (connection *Connection) GetArtists() (Indexes, error) {
query := defaultQuery(connection)
requestUrl := connection.Host + "/rest/getArtists" + "?" + query.Encode()
Expand Down

0 comments on commit 2cc455f

Please sign in to comment.