A collection movie's overview renders in a popup that does not scroll, so a long overview overflows with no way to read the rest. The popup now scrolls. The popup owns its own ScrollableText, built from the selected collection movie's overview when it opens and torn down on Esc so a reopened popup starts at the top. Scrolling mutates only that owned state. The background renders the Collection record's overview and the movies table, neither of which carries a scroll offset, so they cannot scroll along with the popup. The popup also gains the loading and absent fallbacks the rest of the tree already has. Give the collection movie fixture an overview distinct from its collection's, and a multi-paragraph one, so the snapshots can tell the two records apart and a scrolled popup is distinguishable from an unscrolled one.
179 lines
4.6 KiB
Rust
179 lines
4.6 KiB
Rust
use super::movie_overview_handler::MovieOverviewHandler;
|
|
use crate::app::App;
|
|
use crate::event::Key;
|
|
use crate::handlers::KeyEventHandler;
|
|
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
|
use crate::matches_key;
|
|
use crate::models::servarr_data::radarr::modals::MovieOverviewModal;
|
|
use crate::models::servarr_data::radarr::radarr_data::{
|
|
ADD_MOVIE_SELECTION_BLOCKS, ActiveRadarrBlock, COLLECTION_DETAILS_BLOCKS,
|
|
EDIT_COLLECTION_SELECTION_BLOCKS,
|
|
};
|
|
use crate::models::stateful_table::StatefulTable;
|
|
use crate::models::{BlockSelectionState, Route, ScrollableText};
|
|
|
|
#[cfg(test)]
|
|
#[path = "collection_details_handler_tests.rs"]
|
|
mod collection_details_handler_tests;
|
|
|
|
pub(super) struct CollectionDetailsHandler<'a, 'b> {
|
|
key: Key,
|
|
app: &'a mut App<'b>,
|
|
active_radarr_block: ActiveRadarrBlock,
|
|
_context: Option<ActiveRadarrBlock>,
|
|
}
|
|
|
|
impl CollectionDetailsHandler<'_, '_> {
|
|
fn build_movie_overview_modal(&mut self) {
|
|
let overview = self
|
|
.app
|
|
.data
|
|
.radarr_data
|
|
.collection_movies
|
|
.current_selection()
|
|
.overview
|
|
.clone();
|
|
|
|
self.app.data.radarr_data.movie_overview_modal = Some(MovieOverviewModal {
|
|
overview: ScrollableText::with_string(overview),
|
|
});
|
|
}
|
|
}
|
|
|
|
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionDetailsHandler<'a, 'b> {
|
|
fn handle(&mut self) {
|
|
if MovieOverviewHandler::accepts(self.active_radarr_block) {
|
|
return MovieOverviewHandler::new(
|
|
self.key,
|
|
self.app,
|
|
self.active_radarr_block,
|
|
self._context,
|
|
)
|
|
.handle();
|
|
}
|
|
|
|
let collection_movies_table_handling_config =
|
|
TableHandlingConfig::new(ActiveRadarrBlock::CollectionDetails.into());
|
|
|
|
if !handle_table(
|
|
self,
|
|
|app| &mut app.data.radarr_data.collection_movies,
|
|
collection_movies_table_handling_config,
|
|
) {
|
|
self.handle_key_event();
|
|
}
|
|
}
|
|
|
|
fn accepts(active_block: ActiveRadarrBlock) -> bool {
|
|
COLLECTION_DETAILS_BLOCKS.contains(&active_block)
|
|
}
|
|
|
|
fn ignore_special_keys(&self) -> bool {
|
|
self.app.ignore_special_keys_for_textbox_input
|
|
}
|
|
|
|
fn new(
|
|
key: Key,
|
|
app: &'a mut App<'b>,
|
|
active_block: ActiveRadarrBlock,
|
|
_context: Option<ActiveRadarrBlock>,
|
|
) -> CollectionDetailsHandler<'a, 'b> {
|
|
CollectionDetailsHandler {
|
|
key,
|
|
app,
|
|
active_radarr_block: active_block,
|
|
_context,
|
|
}
|
|
}
|
|
|
|
fn get_key(&self) -> Key {
|
|
self.key
|
|
}
|
|
|
|
fn is_ready(&self) -> bool {
|
|
!self.app.is_loading && !self.app.data.radarr_data.collection_movies.is_empty()
|
|
}
|
|
|
|
fn handle_scroll_up(&mut self) {}
|
|
|
|
fn handle_scroll_down(&mut self) {}
|
|
|
|
fn handle_home(&mut self) {}
|
|
|
|
fn handle_end(&mut self) {}
|
|
|
|
fn handle_delete(&mut self) {}
|
|
|
|
fn handle_left_right_action(&mut self) {}
|
|
|
|
fn handle_submit(&mut self) {
|
|
if ActiveRadarrBlock::CollectionDetails == self.active_radarr_block {
|
|
let tmdb_id = self
|
|
.app
|
|
.data
|
|
.radarr_data
|
|
.collection_movies
|
|
.current_selection()
|
|
.tmdb_id;
|
|
|
|
if self
|
|
.app
|
|
.data
|
|
.radarr_data
|
|
.movies
|
|
.items
|
|
.iter()
|
|
.any(|movie| movie.tmdb_id == tmdb_id)
|
|
{
|
|
self.build_movie_overview_modal();
|
|
self
|
|
.app
|
|
.push_navigation_stack(ActiveRadarrBlock::ViewMovieOverview.into());
|
|
} else {
|
|
self.app.push_navigation_stack(
|
|
(
|
|
ActiveRadarrBlock::AddMoviePrompt,
|
|
Some(ActiveRadarrBlock::CollectionDetails),
|
|
)
|
|
.into(),
|
|
);
|
|
self.app.data.radarr_data.selected_block =
|
|
BlockSelectionState::new(ADD_MOVIE_SELECTION_BLOCKS);
|
|
self.app.data.radarr_data.add_movie_modal = Some((&self.app.data.radarr_data).into());
|
|
}
|
|
}
|
|
}
|
|
|
|
fn handle_esc(&mut self) {
|
|
if self.active_radarr_block == ActiveRadarrBlock::CollectionDetails {
|
|
self.app.data.radarr_data.collection_movies = StatefulTable::default();
|
|
self.app.pop_navigation_stack();
|
|
}
|
|
}
|
|
|
|
fn handle_char_key_event(&mut self) {
|
|
if self.active_radarr_block == ActiveRadarrBlock::CollectionDetails
|
|
&& matches_key!(edit, self.key)
|
|
{
|
|
self.app.push_navigation_stack(
|
|
(
|
|
ActiveRadarrBlock::EditCollectionPrompt,
|
|
Some(self.active_radarr_block),
|
|
)
|
|
.into(),
|
|
);
|
|
self.app.data.radarr_data.edit_collection_modal = Some((&self.app.data.radarr_data).into());
|
|
self.app.data.radarr_data.selected_block =
|
|
BlockSelectionState::new(EDIT_COLLECTION_SELECTION_BLOCKS);
|
|
}
|
|
}
|
|
|
|
fn app_mut(&mut self) -> &mut App<'b> {
|
|
self.app
|
|
}
|
|
|
|
fn current_route(&self) -> Route {
|
|
self.app.get_current_route()
|
|
}
|
|
}
|