Successful implementation of movie adding and deleting, and refactored network logic to be more reusable later
This commit is contained in:
+12
-6
@@ -43,16 +43,22 @@ pub trait KeyEventHandler<'a, T: Into<Route>> {
|
||||
}
|
||||
|
||||
pub fn handle_events(key: Key, app: &mut App) {
|
||||
match app.get_current_route().clone() {
|
||||
Route::Radarr(active_radarr_block) => {
|
||||
RadarrHandler::with(&key, app, &active_radarr_block).handle()
|
||||
}
|
||||
_ => (),
|
||||
if let Route::Radarr(active_radarr_block) = app.get_current_route().clone() {
|
||||
RadarrHandler::with(&key, app, &active_radarr_block).handle()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_clear_errors(app: &mut App) {
|
||||
fn handle_clear_errors(app: &mut App) {
|
||||
if !app.error.text.is_empty() {
|
||||
app.error = HorizontallyScrollableText::default();
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_prompt_toggle(app: &mut App, key: &Key) {
|
||||
match key {
|
||||
_ if *key == DEFAULT_KEYBINDINGS.left.key || *key == DEFAULT_KEYBINDINGS.right.key => {
|
||||
app.data.radarr_data.prompt_confirm = !app.data.radarr_data.prompt_confirm;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::radarr::ActiveRadarrBlock;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::handlers::{handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::{Scrollable, StatefulTable};
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{App, Key};
|
||||
|
||||
pub(super) struct AddMovieHandler<'a> {
|
||||
@@ -28,44 +29,36 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for AddMovieHandler<'a> {
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::AddMovieSearchResults => {
|
||||
self.app.data.radarr_data.add_searched_movies.scroll_up()
|
||||
}
|
||||
_ => (),
|
||||
if self.active_radarr_block == &ActiveRadarrBlock::AddMovieSearchResults {
|
||||
self.app.data.radarr_data.add_searched_movies.scroll_up()
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_scroll_down(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::AddMovieSearchResults => {
|
||||
self.app.data.radarr_data.add_searched_movies.scroll_down()
|
||||
}
|
||||
_ => (),
|
||||
if self.active_radarr_block == &ActiveRadarrBlock::AddMovieSearchResults {
|
||||
self.app.data.radarr_data.add_searched_movies.scroll_down()
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_home(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::AddMovieSearchResults => self
|
||||
if self.active_radarr_block == &ActiveRadarrBlock::AddMovieSearchResults {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.scroll_to_top(),
|
||||
_ => (),
|
||||
.scroll_to_top()
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_end(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::AddMovieSearchResults => self
|
||||
if self.active_radarr_block == &ActiveRadarrBlock::AddMovieSearchResults {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.scroll_to_bottom(),
|
||||
_ => (),
|
||||
.scroll_to_bottom()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,14 +66,7 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for AddMovieHandler<'a> {
|
||||
|
||||
fn handle_left_right_action(&mut self) {
|
||||
if *self.active_radarr_block == ActiveRadarrBlock::AddMoviePrompt {
|
||||
match self.key {
|
||||
_ if *self.key == DEFAULT_KEYBINDINGS.left.key
|
||||
|| *self.key == DEFAULT_KEYBINDINGS.right.key =>
|
||||
{
|
||||
self.app.data.radarr_data.prompt_confirm = !self.app.data.radarr_data.prompt_confirm;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
handle_prompt_toggle(self.app, self.key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +83,14 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for AddMovieHandler<'a> {
|
||||
.app
|
||||
.push_navigation_stack(ActiveRadarrBlock::AddMoviePrompt.into());
|
||||
}
|
||||
ActiveRadarrBlock::AddMoviePrompt => {
|
||||
if self.app.data.radarr_data.prompt_confirm {
|
||||
self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::AddMovie);
|
||||
self.app.pop_navigation_stack();
|
||||
} else {
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
@@ -123,8 +117,8 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for AddMovieHandler<'a> {
|
||||
|
||||
fn handle_char_key_event(&mut self) {
|
||||
let key = self.key;
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::AddMovieSearchInput => match self.key {
|
||||
if self.active_radarr_block == &ActiveRadarrBlock::AddMovieSearchInput {
|
||||
match self.key {
|
||||
_ if *key == DEFAULT_KEYBINDINGS.backspace.key => {
|
||||
self.app.data.radarr_data.search.pop();
|
||||
}
|
||||
@@ -132,8 +126,7 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for AddMovieHandler<'a> {
|
||||
self.app.data.radarr_data.search.push(*character);
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ use crate::app::radarr::ActiveRadarrBlock;
|
||||
use crate::handlers::radarr_handlers::add_movie_handler::AddMovieHandler;
|
||||
use crate::handlers::radarr_handlers::collection_details_handler::CollectionDetailsHandler;
|
||||
use crate::handlers::radarr_handlers::movie_details_handler::MovieDetailsHandler;
|
||||
use crate::handlers::{handle_clear_errors, KeyEventHandler};
|
||||
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::Scrollable;
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::utils::strip_non_alphanumeric_characters;
|
||||
use crate::{App, Key};
|
||||
|
||||
@@ -217,14 +218,7 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for RadarrHandler<'a> {
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
ActiveRadarrBlock::DeleteMoviePrompt => match self.key {
|
||||
_ if *self.key == DEFAULT_KEYBINDINGS.left.key
|
||||
|| *self.key == DEFAULT_KEYBINDINGS.right.key =>
|
||||
{
|
||||
self.app.data.radarr_data.prompt_confirm = !self.app.data.radarr_data.prompt_confirm;
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
ActiveRadarrBlock::DeleteMoviePrompt => handle_prompt_toggle(self.app, self.key),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
@@ -292,7 +286,10 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for RadarrHandler<'a> {
|
||||
}
|
||||
}
|
||||
ActiveRadarrBlock::DeleteMoviePrompt => {
|
||||
self.app.should_refresh = self.app.data.radarr_data.prompt_confirm;
|
||||
if self.app.data.radarr_data.prompt_confirm {
|
||||
self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::DeleteMovie);
|
||||
}
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
|
||||
Reference in New Issue
Block a user