subsonic-tui/internal/tui/views/artists.go

71 lines
1.4 KiB
Go
Raw Normal View History

package views
import (
"git.dayanhub.com/sagi/subsonic-tui/internal/client"
"github.com/delucks/go-subsonic"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
var _ View = &artists{}
type artists struct {
view *tview.Table
client *client.Client
artists []*subsonic.ArtistID3
selectArtistFunc func(artistId string)
openArtistFunc func(artistId string)
}
func NewArtists(client *client.Client) *artists {
list := tview.NewTable()
list.SetBackgroundColor(tcell.ColorBlack)
list.SetTitle("Artists [1]")
list.SetBorder(true)
list.SetFocusFunc(func() {
list.SetBorderColor(tcell.ColorRed)
list.SetSelectable(true, false)
})
list.SetBlurFunc(func() {
list.SetBorderColor(tcell.ColorWhite)
list.SetSelectable(false, false)
})
arts, _ := client.GetArtists()
for i, artist := range arts {
cell := tview.NewTableCell(artist.Name).SetExpansion(1)
list.SetCell(i, 0, cell)
//list.AddItem(artist.Name, fmt.Sprintf("%s", artist.Name), '0', nil)
}
resp := &artists{
view: list,
client: client,
artists: arts,
}
list.SetSelectedFunc(func(row, column int) {
resp.openArtistFunc(resp.artists[row].ID)
})
return resp
}
func (a *artists) SetSelectArtistFunc(f func(artistId string)) {
a.selectArtistFunc = f
}
func (a *artists) SetOpenArtistFunc(f func(artistId string)) {
a.openArtistFunc = f
}
func (a *artists) Update() {
}
func (a *artists) GetView() tview.Primitive {
return a.view
}