| @@ -13,14 +13,12 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()> |
| 13 | 13 | | KeyCode::Char('k') | KeyCode::Up => app.append_list.prev(), |
| 14 | 14 | | |
| 15 | 15 | | KeyCode::Enter => { |
| 16 | | − | let pl_index = app.append_list.index; |
| 17 | | − | let pl_name = &app.append_list.list.get(pl_index).unwrap(); |
| 16 | + | // name of highlighted playlist in append list |
| 17 | + | let pl_name = &app.append_list.get_item_at_current_index(); |
| 18 | 18 | | |
| 19 | | − | let s_index: usize; |
| 20 | 19 | | match app.selected_tab { |
| 21 | 20 | | SelectedTab::Queue => { |
| 22 | | − | s_index = app.queue_list.index; |
| 23 | | − | let short_path = &app.queue_list.list.get(s_index).unwrap().file; |
| 21 | + | let short_path = &app.queue_list.get_item_at_current_index().file; |
| 24 | 22 | | |
| 25 | 23 | | if let Some(full_path) = app.conn.get_full_path(short_path) { |
| 26 | 24 | | let song = app.conn.get_song_with_only_filename(&full_path); |
| @@ -68,7 +66,23 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()> |
| 68 | 66 | | } |
| 69 | 67 | | } |
| 70 | 68 | | } |
| 71 | | − | _ => {} |
| 69 | + | |
| 70 | + | SelectedTab::Playlists => { |
| 71 | + | let playlist_name = app.pl_list.get_item_at_current_index(); |
| 72 | + | if *pl_name == "Current Playlist" { |
| 73 | + | app.conn.load_playlist(playlist_name)?; |
| 74 | + | app.update_queue(); |
| 75 | + | } else { |
| 76 | + | let songs = app.conn.conn.playlist(playlist_name)?; |
| 77 | + | for song in songs { |
| 78 | + | // We ignore the Err() since there could be songs in playlists, which do not exist in the db anymore. |
| 79 | + | // So instead of panicking, we just ignore if the song does not exists |
| 80 | + | app.conn |
| 81 | + | .add_to_playlist(*pl_name, &song) |
| 82 | + | .unwrap_or_else(|_| {}); |
| 83 | + | } |
| 84 | + | } |
| 85 | + | } |
| 72 | 86 | | } |
| 73 | 87 | | |
| 74 | 88 | | // hide the playlist popup |