From 1072df58e801e11095608cf48061c2e9d8319915 Mon Sep 17 00:00:00 2001 From: RicardoHE97 Date: Mon, 22 Jun 2020 15:04:49 -0700 Subject: [PATCH 1/2] Add feature to like a song from basic view Add the feature to like a song with the 's' key when you are in the basic view. --- src/handlers/basic_view.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/handlers/basic_view.rs b/src/handlers/basic_view.rs index d9480082..697316b4 100644 --- a/src/handlers/basic_view.rs +++ b/src/handlers/basic_view.rs @@ -1,3 +1,16 @@ -use crate::{app::App, event::Key}; +use crate::{app::App, event::Key, network::IoEvent}; -pub fn handler(_key: Key, _app: &mut App) {} +pub fn handler(key: Key, app: &mut App) { + match key { + Key::Char('s') => { + if let Some(playing_context) = &app.current_playback_context { + if let Some(track) = &playing_context.clone().item { + if let Some(id) = &track.id { + app.dispatch(IoEvent::ToggleSaveTrack(id.to_string())); + } + } + } + } + _ => {} + }; +} From ee9c79e998dbfc301ef4fc8cbd2152471223c942 Mon Sep 17 00:00:00 2001 From: RicardoHE97 Date: Mon, 22 Jun 2020 22:01:25 -0700 Subject: [PATCH 2/2] Reformat code for basic_view.rs that fix a common mistake --- src/handlers/basic_view.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/handlers/basic_view.rs b/src/handlers/basic_view.rs index 697316b4..a2f10d1e 100644 --- a/src/handlers/basic_view.rs +++ b/src/handlers/basic_view.rs @@ -1,16 +1,13 @@ use crate::{app::App, event::Key, network::IoEvent}; pub fn handler(key: Key, app: &mut App) { - match key { - Key::Char('s') => { - if let Some(playing_context) = &app.current_playback_context { - if let Some(track) = &playing_context.clone().item { - if let Some(id) = &track.id { - app.dispatch(IoEvent::ToggleSaveTrack(id.to_string())); - } + if let Key::Char('s') = key { + if let Some(playing_context) = &app.current_playback_context { + if let Some(track) = &playing_context.clone().item { + if let Some(id) = &track.id { + app.dispatch(IoEvent::ToggleSaveTrack(id.to_string())); } } } - _ => {} - }; + } }