Implement QueueEntry for album_view

This commit is contained in:
aditya-K2
2023-12-17 15:18:43 +05:30
parent 1076cb816f
commit 0001306f7e
3 changed files with 18 additions and 1 deletions

View File

@@ -104,6 +104,7 @@ var (
"album_view": {
"normal": {
{R: 'a'}: "add_to_playlist",
{R: 'q'}: "queue_entry",
},
"visual": {
{R: 'a'}: "add_to_playlist",

View File

@@ -358,13 +358,17 @@ func NewApplication() *tview.Application {
"queue_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
albumsView.QueueEntry()
return nil
}, progressBar),
}, nil),
}))
albumView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{
"add_to_playlist": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
albumView.AddToPlaylist()
return nil
}, nil),
"queue_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey {
albumView.QueueEntry()
return nil
}, nil),
}))
// Visual Actions

View File

@@ -1,6 +1,8 @@
package ui
import (
"fmt"
"github.com/aditya-K2/gspt/spt"
"github.com/gdamore/tcell/v2"
"github.com/zmb3/spotify/v2"
@@ -64,6 +66,16 @@ func (a *AlbumView) AddToPlaylist() {
addToPlaylist([]spotify.ID{track.ID})
}
func (a *AlbumView) QueueEntry() {
r, _ := Main.GetSelection()
track := (*(*a.currentFullAlbum).Tracks)[r]
msg := fmt.Sprintf("%s queued succesfully!", track.Name)
if err := spt.QueueTracks(track.ID); err != nil {
msg = err.Error()
}
SendNotification(msg)
}
func (a *AlbumView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
addToPlaylist(Map((*(*a.currentFullAlbum).Tracks)[start:end+1],
func(s spotify.SimpleTrack) spotify.ID {