Skip to content

Commit

Permalink
feature: #76, clarify search results
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxserxxx committed Oct 15, 2024
1 parent 617c588 commit 6d2d4fd
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions page_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main

import (
"sort"
"strings"

"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
Expand Down Expand Up @@ -46,23 +47,23 @@ func (ui *Ui) createSearchPage() *SearchPage {
searchPage.artistList = tview.NewList().
ShowSecondaryText(false)
searchPage.artistList.Box.
SetTitle(" artist ").
SetTitle(" artist matches ").
SetTitleAlign(tview.AlignLeft).
SetBorder(true)

// album list
searchPage.albumList = tview.NewList().
ShowSecondaryText(false)
searchPage.albumList.Box.
SetTitle(" album ").
SetTitle(" album matches ").
SetTitleAlign(tview.AlignLeft).
SetBorder(true)

// song list
searchPage.songList = tview.NewList().
ShowSecondaryText(false)
searchPage.songList.Box.
SetTitle(" song ").
SetTitle(" song matches ").
SetTitleAlign(tview.AlignLeft).
SetBorder(true)

Expand Down Expand Up @@ -211,6 +212,7 @@ func (ui *Ui) createSearchPage() *SearchPage {
return &searchPage
}

// TODO fork this off and search until there are no more results
func (s *SearchPage) search() {
if len(s.searchField.GetText()) == 0 {
return
Expand All @@ -223,17 +225,24 @@ func (s *SearchPage) search() {
return
}

query = strings.ToLower(query)
for _, artist := range res.SearchResults.Artist {
s.artistList.AddItem(tview.Escape(artist.Name), "", 0, nil)
s.artists = append(s.artists, &artist)
if strings.Contains(strings.ToLower(artist.Name), query) {
s.artistList.AddItem(tview.Escape(artist.Name), "", 0, nil)
s.artists = append(s.artists, &artist)
}
}
for _, album := range res.SearchResults.Album {
s.albumList.AddItem(tview.Escape(album.Name), "", 0, nil)
s.albums = append(s.albums, &album)
if strings.Contains(strings.ToLower(album.Name), query) {
s.albumList.AddItem(tview.Escape(album.Name), "", 0, nil)
s.albums = append(s.albums, &album)
}
}
for _, song := range res.SearchResults.Song {
s.songList.AddItem(tview.Escape(song.Title), "", 0, nil)
s.songs = append(s.songs, &song)
if strings.Contains(strings.ToLower(song.Title), query) {
s.songList.AddItem(tview.Escape(song.Title), "", 0, nil)
s.songs = append(s.songs, &song)
}
}

s.artistOffset += len(res.SearchResults.Artist)
Expand Down

0 comments on commit 6d2d4fd

Please sign in to comment.