Refactor some views

This commit is contained in:
aditya-K2
2023-04-29 18:18:50 +05:30
parent 4170dfbde0
commit c26fd2b98b
4 changed files with 13 additions and 8 deletions

View File

@@ -62,13 +62,15 @@ func (a *AlbumView) Content() func() [][]Content {
func (a *AlbumView) AddToPlaylist() {
r, _ := Main.Table.GetSelection()
addToPlaylist([]spotify.ID{(*(*a.currentFullAlbum).Tracks)[r].ID})
track := (*(*a.currentFullAlbum).Tracks)[r]
addToPlaylist([]spotify.ID{track.ID})
}
func (a *AlbumView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
tracks := make([]spotify.ID, 0)
sTracks := (*(*a.currentFullAlbum).Tracks)
for k := start; k <= end; k++ {
tracks = append(tracks, (*(*a.currentFullAlbum).Tracks)[k].ID)
tracks = append(tracks, sTracks[k].ID)
}
addToPlaylist(tracks)
return nil

View File

@@ -61,12 +61,13 @@ func (a *AlbumsView) PlaySelectEntry() {
func (a *AlbumsView) QueueSelectEntry() {
r, _ := Main.Table.GetSelection()
msg := SendNotificationWithChan("Queueing Album...")
alb := (*a.savedAlbums)[r]
msg := SendNotificationWithChan("Queueing " + alb.Name + "...")
go func() {
if err := spt.QueueAlbum((*a.savedAlbums)[r].ID); err != nil {
if err := spt.QueueAlbum(alb.ID); err != nil {
msg <- err.Error()
} else {
msg <- "Album Queued: " + ((*a.savedAlbums)[r].Name) + "!"
msg <- (alb.Name) + " queued succesfully!"
}
}()
}

View File

@@ -66,8 +66,9 @@ func (p *PlaylistView) AddToPlaylist() {
func (p *PlaylistView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
tracks := make([]spotify.ID, 0)
sTracks := (*(*p.currentUserFullPlaylist).Tracks)
for k := start; k <= end; k++ {
tracks = append(tracks, (*(*p.currentUserFullPlaylist).Tracks)[k].Track.ID)
tracks = append(tracks, sTracks[k].Track.ID)
}
addToPlaylist(tracks)
return nil

View File

@@ -67,13 +67,14 @@ func (r *RecentlyPlayedView) RefreshState() {
func (re *RecentlyPlayedView) SelectEntry(e *tcell.EventKey) *tcell.EventKey {
r, _ := Main.Table.GetSelection()
trackUri := re.recentlyPlayed[r].Track.URI
contextUri := re.recentlyPlayed[r].PlaybackContext.URI
if string(contextUri) != "" {
if err := spt.PlaySongWithContextURI(&re.recentlyPlayed[r].PlaybackContext.URI, &re.recentlyPlayed[r].Track.URI); err != nil {
if err := spt.PlaySongWithContextURI(&contextUri, &trackUri); err != nil {
SendNotification(err.Error())
}
} else {
if err := spt.PlaySong(re.recentlyPlayed[r].Track.URI); err != nil {
if err := spt.PlaySong(trackUri); err != nil {
SendNotification(err.Error())
}
}