From e8d51d0d2b2ffb576cf1f9dcb5af645b858ef44e Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Sun, 17 Dec 2023 16:10:21 +0530 Subject: [PATCH] Implement QueueEntry for artist_view --- config/key.go | 1 + ui/app.go | 4 ++++ ui/view_artist.go | 19 ++++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/config/key.go b/config/key.go index 069b02d..60c4906 100644 --- a/config/key.go +++ b/config/key.go @@ -93,6 +93,7 @@ var ( "artist_view": { "normal": { {K: tcell.KeyCtrlP}: "play_entry", + {R: 'q'}: "queue_entry", }, }, "albums_view": { diff --git a/ui/app.go b/ui/app.go index 190a61e..3dcdc4a 100644 --- a/ui/app.go +++ b/ui/app.go @@ -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 { diff --git a/ui/view_artist.go b/ui/view_artist.go index 5d8a459..5dd7d50 100644 --- a/ui/view_artist.go +++ b/ui/view_artist.go @@ -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" }