Implement QueueEntry for artist_view

This commit is contained in:
aditya-K2
2023-12-17 16:10:21 +05:30
parent b34d9b608e
commit e8d51d0d2b
3 changed files with 23 additions and 1 deletions

View File

@@ -93,6 +93,7 @@ var (
"artist_view": {
"normal": {
{K: tcell.KeyCtrlP}: "play_entry",
{R: 'q'}: "queue_entry",
},
},
"albums_view": {

View File

@@ -349,6 +349,10 @@ func NewApplication() *tview.Application {
artistView.PlayEntry()
return nil
}, progressBar),
"queue_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
artistView.QueueEntry()
return nil
}, nil),
}))
albumsView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{
"play_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey {

View File

@@ -1,6 +1,8 @@
package ui
import (
"fmt"
"github.com/aditya-K2/gspt/spt"
"github.com/zmb3/spotify/v2"
)
@@ -101,7 +103,22 @@ func (a *ArtistView) OpenEntry() {
})
}
func (a *ArtistsView) QueueEntry() {
func (a *ArtistView) QueueEntry() {
a.handle(func(r int) {
msg := SendNotificationWithChan(fmt.Sprintf("Queueing %s...", a.albums[r].Name))
go func() {
if err := spt.QueueAlbum(a.albums[r].ID); err != nil {
msg <- err.Error()
}
msg <- fmt.Sprintf("%s queued succesfully!", a.albums[r].Name)
}()
}, func(r int) {
msg := fmt.Sprintf("%s queued succesfully!", a.topTracks[r].Name)
if err := spt.QueueTracks(a.topTracks[r].ID); err != nil {
msg = err.Error()
}
SendNotification(msg)
})
}
func (a *ArtistView) Name() string { return "AlbumsView" }