Implement QueueSongsVisual for recently_played_view

This commit is contained in:
aditya-K2
2023-12-17 14:52:14 +05:30
parent 9e4d9a97ee
commit 9f73b4bb06
3 changed files with 18 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ var (
},
"visual": {
{R: 'a'}: "add_to_playlist",
{R: 'q'}: "queue_entry",
},
},
"search_view": {

View File

@@ -374,6 +374,7 @@ func NewApplication() *tview.Application {
})
recentlyPlayedView.SetVisualActions(map[string]func(start, end int, e *tcell.EventKey) *tcell.EventKey{
"add_to_playlist": recentlyPlayedView.AddToPlaylistVisual,
"queue_entry": recentlyPlayedView.QueueSongsVisual,
})
playlistView.SetVisualActions(map[string]func(start, end int, e *tcell.EventKey) *tcell.EventKey{
"add_to_playlist": playlistView.AddToPlaylistVisual,

View File

@@ -49,6 +49,22 @@ func (r *RecentlyPlayedView) AddToPlaylistVisual(start, end int, e *tcell.EventK
return nil
}
func (r *RecentlyPlayedView) QueueSongsVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
tracks := r.recentlyPlayed[start : end+1]
msg := SendNotificationWithChan(fmt.Sprintf("Queueing %d tracks...", len(tracks)))
go func() {
err := spt.QueueTracks(Map(tracks,
func(s spotify.RecentlyPlayedItem) spotify.ID {
return s.Track.ID
})...)
if err != nil {
msg <- err.Error()
}
msg <- fmt.Sprintf("Queued %d tracks!", len(tracks))
}()
return nil
}
func (r *RecentlyPlayedView) Name() string { return "RecentlyPlayedView" }
func (r *RecentlyPlayedView) RefreshState() {