From c26fd2b98b0876e22ed9f08d609a7a2c471b0409 Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Sat, 29 Apr 2023 18:18:50 +0530 Subject: [PATCH] Refactor some views --- ui/view_album.go | 6 ++++-- ui/view_albums.go | 7 ++++--- ui/view_playlist.go | 3 ++- ui/view_recent.go | 5 +++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ui/view_album.go b/ui/view_album.go index d45eefd..1fe6bd2 100644 --- a/ui/view_album.go +++ b/ui/view_album.go @@ -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 diff --git a/ui/view_albums.go b/ui/view_albums.go index 89ea3bc..3235a96 100644 --- a/ui/view_albums.go +++ b/ui/view_albums.go @@ -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!" } }() } diff --git a/ui/view_playlist.go b/ui/view_playlist.go index 631b66b..91ce9c9 100644 --- a/ui/view_playlist.go +++ b/ui/view_playlist.go @@ -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 diff --git a/ui/view_recent.go b/ui/view_recent.go index 378af0a..e5173a2 100644 --- a/ui/view_recent.go +++ b/ui/view_recent.go @@ -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()) } }