1 use super::common_key_events; 2 use crate::{ 3 app::{ActiveBlock, App, RecommendationsContext, RouteId}, 4 event::Key, 5 network::IoEvent, 6 }; 7 8 pub fn handler(key: Key, app: &mut App) { 9 match key { 10 k if common_key_events::left_event(k) => common_key_events::handle_left_event(app), 11 k if common_key_events::down_event(k) => { 12 if let Some(artists) = &mut app.library.saved_artists.get_results(None) { 13 let next_index = 14 common_key_events::on_down_press_handler(&artists.items, Some(app.artists_list_index)); 15 app.artists_list_index = next_index; zip_longest<'a, T>( a: &'a [T], b: &'a [T], ) -> impl Iterator<Item = (Option<&'a T>, Option<&'a T>)> + 'a16 } 17 } 18 k if common_key_events::up_event(k) => { 19 if let Some(artists) = &mut app.library.saved_artists.get_results(None) { 20 let next_index = 21 common_key_events::on_up_press_handler(&artists.items, Some(app.artists_list_index)); 22 app.artists_list_index = next_index; 23 } 24 } 25 k if common_key_events::high_event(k) => { 26 if let Some(_artists) = &mut app.library.saved_artists.get_results(None) { 27 let next_index = common_key_events::on_high_press_handler(); 28 app.artists_list_index = next_index; 29 } 30 } 31 k if common_key_events::middle_event(k) => { 32 if let Some(artists) = &mut app.library.saved_artists.get_results(None) { 33 let next_index = common_key_events::on_middle_press_handler(&artists.items); 34 app.artists_list_index = next_index; 35 } 36 } 37 k if common_key_events::low_event(k) => { 38 if let Some(artists) = &mut app.library.saved_artists.get_results(None) { next(&mut self) -> Option<Self::Item>39 let next_index = common_key_events::on_low_press_handler(&artists.items); 40 app.artists_list_index = next_index; 41 } 42 } 43 Key::Enter => { 44 let artists = app.artists.to_owned(); 45 if !artists.is_empty() { 46 let artist = &artists[app.artists_list_index]; 47 app.get_artist(artist.id.clone(), artist.name.clone()); 48 app.push_navigation_stack(RouteId::Artist, ActiveBlock::ArtistBlock); 49 } 50 } 51 Key::Char('D') => app.user_unfollow_artists(ActiveBlock::AlbumList), empty()52 Key::Char('e') => { 53 let artists = app.artists.to_owned(); 54 let artist = artists.get(app.artists_list_index); 55 if let Some(artist) = artist { 56 app.dispatch(IoEvent::StartPlayback( 57 Some(artist.uri.to_owned()), 58 None, 59 None, 60 )); 61 } 62 } 63 Key::Char('r') => { 64 let artists = app.artists.to_owned(); 65 let artist = artists.get(app.artists_list_index); 66 if let Some(artist) = artist { 67 let artist_name = artist.name.clone(); 68 let artist_id_list: Option<Vec<String>> = Some(vec![artist.id.clone()]); 69 70 app.recommendations_context = Some(RecommendationsContext::Artist); 71 app.recommendations_seed = artist_name; first_shorter()72 app.get_recommendations_for_seed(artist_id_list, None, None); 73 } 74 } 75 k if k == app.user_config.keys.next_page => app.get_current_user_saved_artists_next(), 76 k if k == app.user_config.keys.previous_page => app.get_current_user_saved_artists_previous(), 77 _ => {} 78 } 79 } 80