Handle track saving in non-album contexts (playlist/Made for you).
Saving of tracks used to only work in album view (handled by:
`src.handlers.album_tracks.handle_save_album_event`).
Add some rough code to get track saving working in other cases. Manually tested
`Playlist` and `Made for you` views.
Fixes Rigellute/spotify-tui#495
@@ -141,6 +141,7 @@ pub fn handler(key: Key, app: &mut App) {
None => {}
};
}
+ Key::Char('s') => handle_save_track_event(app),
Key::Char('S') => play_random_song(app),
Key::Ctrl('e') => jump_to_end(app),
Key::Ctrl('a') => jump_to_start(app),
@@ -252,6 +253,15 @@ fn play_random_song(app: &mut App) {
};
}
+fn handle_save_track_event(app: &mut App) {
+ let (selected_index, tracks) = (&app.track_table.selected_index, &app.track_table.tracks);
+ if let Some(track) = tracks.get(*selected_index) {
+ if let Some(id) = &track.id {
+ app.dispatch(IoEvent::ToggleSaveTrack(id.to_string()));
+ };
+ };
+}
+
fn handle_recommended_tracks(app: &mut App) {
let (selected_index, tracks) = (&app.track_table.selected_index, &app.track_table.tracks);
if let Some(track) = tracks.get(*selected_index) {
