Sagi Dayan
92e3c4ea7d
All checks were successful
ci / check for spelling errors (pull_request) Successful in 21s
ci / code quality (lint/tests) (pull_request) Successful in 2m29s
ci / Make sure build does not fail (pull_request) Successful in 2m25s
ci / notify-fail (pull_request) Has been skipped
ci / check for spelling errors (push) Successful in 22s
ci / code quality (lint/tests) (push) Successful in 1m53s
ci / Make sure build does not fail (push) Successful in 2m55s
ci / notify-fail (push) Has been skipped
Signed-off-by: Sagi Dayan <sagidayan@gmail.com>
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package views
|
|
|
|
import (
|
|
"git.dayanhub.com/sagi/subsonic-tui/internal/client"
|
|
"git.dayanhub.com/sagi/subsonic-tui/internal/config"
|
|
"github.com/delucks/go-subsonic"
|
|
"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(config.ColorBackground)
|
|
list.SetTitle("Artists [1]")
|
|
list.SetBorder(true)
|
|
list.SetFocusFunc(func() {
|
|
list.SetBorderColor(config.ColorSelectedBoarder)
|
|
list.SetSelectable(true, false)
|
|
})
|
|
list.SetBlurFunc(func() {
|
|
list.SetBorderColor(config.ColorBluredBoarder)
|
|
list.SetSelectable(false, false)
|
|
})
|
|
|
|
arts, _ := client.GetArtists()
|
|
|
|
for i, artist := range arts {
|
|
cell := tview.NewTableCell(artist.Name).SetExpansion(1)
|
|
list.SetCell(i, 0, cell)
|
|
}
|
|
|
|
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
|
|
}
|