From 503701691b3f9e10bef93361eef7e51822b82cf7 Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Wed, 14 Sep 2022 19:51:06 +0530 Subject: [PATCH] Change deleteSongFromPlaylist and clearPlaylist --- main.go | 10 +++++++--- views/playlistview.go | 14 ++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 2147a95..4b12019 100644 --- a/main.go +++ b/main.go @@ -118,7 +118,7 @@ func main() { // This Function Is Responsible for Changing the Focus it uses the Focus Map and Based on it Chooses // the Draw Function views.PView.StartWatcher() - views.SetCurrentView(views.PView) + views.SetCurrentView(&views.PView) ui.Ui.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) { views.GetCurrentView().Update(ui.Ui.ExpandedView) return ui.Ui.ExpandedView.GetInnerRect() @@ -148,7 +148,11 @@ func main() { if err := Conn.Clear(); err != nil { notify.Notify.Send("Could not Clear the Playlist") } else { - notify.Notify.Send("Playlist Cleared") + if views.PView.Playlist, err = client.Conn.PlaylistInfo(-1, -1); err != nil { + utils.Print("RED", "Couldn't get the current Playlist.\n") + panic(err) + } + notify.Notify.Send("Playlist Cleared!") } }, "previousSong": func() { @@ -195,7 +199,7 @@ func main() { views.FView.Update(ui.Ui.ExpandedView) }, "navigateToPlaylist": func() { - views.SetCurrentView(views.PView) + views.SetCurrentView(&views.PView) ui.Ui.Navbar.Select(0, 0) views.PView.Update(ui.Ui.ExpandedView) }, diff --git a/views/playlistview.go b/views/playlistview.go index 9af3cb1..9aab0d4 100644 --- a/views/playlistview.go +++ b/views/playlistview.go @@ -50,22 +50,24 @@ func (p PlaylistView) Quit() { func (p PlaylistView) FocusBuffSearchView() {} -func (p PlaylistView) DeleteSongFromPlaylist() { +func (p *PlaylistView) DeleteSongFromPlaylist() { UI := ui.Ui CONN := client.Conn r, _ := UI.ExpandedView.GetSelection() if err := CONN.Delete(r, -1); err != nil { notify.Notify.Send("Could not Remove the Song from Playlist") + } else { + if p.Playlist, err = client.Conn.PlaylistInfo(-1, -1); err != nil { + utils.Print("RED", "Couldn't get the current Playlist.\n") + panic(err) + } } + } func (p PlaylistView) Update(inputTable *tview.Table) { inputTable.Clear() - cplaylist := make([]mpd.Attrs, len(p.Playlist)) - for k, v := range p.Playlist { - cplaylist[k] = v - } - for i, j := range cplaylist { + for i, j := range p.Playlist { _, _, w, _ := inputTable.GetInnerRect() if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" { inputTable.SetCell(i, 0,