Implement QueueSelectedEntry for top_tracks_view

This commit is contained in:
aditya-K2
2023-05-19 01:08:54 +05:30
parent 30c87834f8
commit 4e0b1c0a41
3 changed files with 18 additions and 0 deletions

View File

@@ -67,6 +67,7 @@ var (
"top_tracks_view": {
"normal": {
{K: tcell.KeyCtrlP}: "play_entry",
{R: 'q'}: "queue_entry",
},
},
"liked_songs_view": {

View File

@@ -308,6 +308,10 @@ func NewApplication() *tview.Application {
topTracksView.PlaySelectedEntry()
return nil
}, progressBar),
"queue_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
topTracksView.QueueSelectedEntry()
return nil
}, nil),
}))
likedSongsView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{
"add_to_playlist": 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"
)
@@ -94,4 +96,15 @@ func (a *TopTracksView) OpenEntry() {
a.handle(trackHandler, artistHandler)
}
func (a *TopTracksView) QueueSelectedEntry() {
a.handle(func(r int) {
msg := fmt.Sprintf("%s Queued Succesfully!", a.topTracks[r-2-len(a.topArtists)].Name)
if err := spt.QueueTracks(a.topTracks[r-2-len(a.topArtists)].ID); err != nil {
msg = err.Error()
}
SendNotification(msg)
}, func(int) { SendNotification("Artists can not be queued!") })
}
func (a *TopTracksView) Name() string { return "TopTracksView" }