refactor(ui): Simplified the popup delegation so all future UI is easier to implement
This commit is contained in:
@@ -5,7 +5,6 @@ use crate::app::App;
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, EDIT_INDEXER_BLOCKS};
|
||||
use crate::models::Route;
|
||||
use crate::render_selectable_input_box;
|
||||
use crate::ui::sonarr_ui::indexers::draw_indexers;
|
||||
use crate::ui::styles::ManagarrStyle;
|
||||
use crate::ui::utils::title_block_centered;
|
||||
use crate::ui::widgets::button::Button;
|
||||
@@ -13,7 +12,7 @@ use crate::ui::widgets::checkbox::Checkbox;
|
||||
use crate::ui::widgets::input_box::InputBox;
|
||||
use crate::ui::widgets::loading_block::LoadingBlock;
|
||||
use crate::ui::widgets::popup::Size;
|
||||
use crate::ui::{draw_popup_over, DrawUi};
|
||||
use crate::ui::{draw_popup, DrawUi};
|
||||
use ratatui::layout::{Constraint, Flex, Layout, Rect};
|
||||
use ratatui::text::Text;
|
||||
use ratatui::widgets::Paragraph;
|
||||
@@ -34,12 +33,10 @@ impl DrawUi for EditIndexerUi {
|
||||
false
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_popup_over(
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, _area: Rect) {
|
||||
draw_popup(
|
||||
f,
|
||||
app,
|
||||
area,
|
||||
draw_indexers,
|
||||
draw_edit_indexer_prompt,
|
||||
Size::WideLargePrompt,
|
||||
);
|
||||
|
||||
@@ -10,14 +10,13 @@ use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||
};
|
||||
use crate::models::Route;
|
||||
use crate::render_selectable_input_box;
|
||||
use crate::ui::sonarr_ui::indexers::draw_indexers;
|
||||
use crate::ui::styles::ManagarrStyle;
|
||||
use crate::ui::utils::title_block_centered;
|
||||
use crate::ui::widgets::button::Button;
|
||||
use crate::ui::widgets::input_box::InputBox;
|
||||
use crate::ui::widgets::loading_block::LoadingBlock;
|
||||
use crate::ui::widgets::popup::Size;
|
||||
use crate::ui::{draw_popup_over, DrawUi};
|
||||
use crate::ui::{draw_popup, DrawUi};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "indexer_settings_ui_tests.rs"]
|
||||
@@ -34,12 +33,10 @@ impl DrawUi for IndexerSettingsUi {
|
||||
false
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_popup_over(
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, _area: Rect) {
|
||||
draw_popup(
|
||||
f,
|
||||
app,
|
||||
area,
|
||||
draw_indexers,
|
||||
draw_edit_indexer_settings_prompt,
|
||||
Size::LargePrompt,
|
||||
);
|
||||
|
||||
@@ -44,62 +44,61 @@ impl DrawUi for IndexersUi {
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
let route = app.get_current_route();
|
||||
let mut indexers_matchers = |active_sonarr_block| match active_sonarr_block {
|
||||
ActiveSonarrBlock::Indexers => draw_indexers(f, app, area),
|
||||
ActiveSonarrBlock::TestIndexer => {
|
||||
draw_indexers(f, app, area);
|
||||
if app.is_loading || app.is_routing {
|
||||
let loading_popup = Popup::new(LoadingBlock::new(
|
||||
app.is_loading,
|
||||
title_block("Testing Indexer"),
|
||||
))
|
||||
.size(Size::LargeMessage);
|
||||
f.render_widget(loading_popup, f.area());
|
||||
} else {
|
||||
let popup = if let Some(result) = app.data.sonarr_data.indexer_test_error.as_ref() {
|
||||
Popup::new(Message::new(result.clone())).size(Size::LargeMessage)
|
||||
} else {
|
||||
let message = Message::new("Indexer test succeeded!")
|
||||
.title("Success")
|
||||
.style(Style::new().success().bold());
|
||||
Popup::new(message).size(Size::Message)
|
||||
};
|
||||
|
||||
f.render_widget(popup, f.area());
|
||||
}
|
||||
}
|
||||
ActiveSonarrBlock::DeleteIndexerPrompt => {
|
||||
let prompt = format!(
|
||||
"Do you really want to delete this indexer: \n{}?",
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexers
|
||||
.current_selection()
|
||||
.name
|
||||
.clone()
|
||||
.unwrap_or_default()
|
||||
);
|
||||
let confirmation_prompt = ConfirmationPrompt::new()
|
||||
.title("Delete Indexer")
|
||||
.prompt(&prompt)
|
||||
.yes_no_value(app.data.sonarr_data.prompt_confirm);
|
||||
|
||||
draw_indexers(f, app, area);
|
||||
f.render_widget(
|
||||
Popup::new(confirmation_prompt).size(Size::MediumPrompt),
|
||||
f.area(),
|
||||
);
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
draw_indexers(f, app, area);
|
||||
|
||||
match route {
|
||||
_ if EditIndexerUi::accepts(route) => EditIndexerUi::draw(f, app, area),
|
||||
_ if IndexerSettingsUi::accepts(route) => IndexerSettingsUi::draw(f, app, area),
|
||||
_ if TestAllIndexersUi::accepts(route) => TestAllIndexersUi::draw(f, app, area),
|
||||
Route::Sonarr(active_sonarr_block, _) if INDEXERS_BLOCKS.contains(&active_sonarr_block) => {
|
||||
indexers_matchers(active_sonarr_block)
|
||||
Route::Sonarr(active_sonarr_block, _) => match active_sonarr_block {
|
||||
ActiveSonarrBlock::TestIndexer => {
|
||||
if app.is_loading || app.data.sonarr_data.indexer_test_errors.is_none() {
|
||||
let loading_popup = Popup::new(LoadingBlock::new(
|
||||
app.is_loading || app.data.sonarr_data.indexer_test_errors.is_none(),
|
||||
title_block("Testing Indexer"),
|
||||
))
|
||||
.size(Size::LargeMessage);
|
||||
f.render_widget(loading_popup, f.area());
|
||||
} else {
|
||||
let popup = {
|
||||
let result = app.data.sonarr_data.indexer_test_errors.as_ref().expect("Test result is unpopulated");
|
||||
|
||||
if !result.is_empty() {
|
||||
Popup::new(Message::new(result.clone())).size(Size::LargeMessage)
|
||||
} else {
|
||||
let message = Message::new("Indexer test succeeded!")
|
||||
.title("Success")
|
||||
.style(Style::new().success().bold());
|
||||
Popup::new(message).size(Size::Message)
|
||||
}
|
||||
};
|
||||
|
||||
f.render_widget(popup, f.area());
|
||||
}
|
||||
}
|
||||
ActiveSonarrBlock::DeleteIndexerPrompt => {
|
||||
let prompt = format!(
|
||||
"Do you really want to delete this indexer: \n{}?",
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexers
|
||||
.current_selection()
|
||||
.name
|
||||
.clone()
|
||||
.unwrap_or_default()
|
||||
);
|
||||
let confirmation_prompt = ConfirmationPrompt::new()
|
||||
.title("Delete Indexer")
|
||||
.prompt(&prompt)
|
||||
.yes_no_value(app.data.sonarr_data.prompt_confirm);
|
||||
|
||||
f.render_widget(
|
||||
Popup::new(confirmation_prompt).size(Size::MediumPrompt),
|
||||
f.area(),
|
||||
);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -3,12 +3,11 @@ use crate::app::App;
|
||||
use crate::models::servarr_data::modals::IndexerTestResultModalItem;
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock;
|
||||
use crate::models::Route;
|
||||
use crate::ui::sonarr_ui::indexers::draw_indexers;
|
||||
use crate::ui::styles::ManagarrStyle;
|
||||
use crate::ui::utils::{borderless_block, get_width_from_percentage, title_block};
|
||||
use crate::ui::widgets::managarr_table::ManagarrTable;
|
||||
use crate::ui::widgets::popup::Size;
|
||||
use crate::ui::{draw_popup_over, DrawUi};
|
||||
use crate::ui::{draw_popup, DrawUi};
|
||||
use ratatui::layout::{Alignment, Constraint, Rect};
|
||||
use ratatui::widgets::{Cell, Row};
|
||||
use ratatui::Frame;
|
||||
@@ -28,12 +27,10 @@ impl DrawUi for TestAllIndexersUi {
|
||||
false
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_popup_over(
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, _area: Rect) {
|
||||
draw_popup(
|
||||
f,
|
||||
app,
|
||||
area,
|
||||
draw_indexers,
|
||||
draw_test_all_indexers_test_results,
|
||||
Size::Large,
|
||||
);
|
||||
@@ -41,6 +38,7 @@ impl DrawUi for TestAllIndexersUi {
|
||||
}
|
||||
|
||||
fn draw_test_all_indexers_test_results(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
let is_loading = app.is_loading || app.data.sonarr_data.indexer_test_all_results.is_none();
|
||||
let current_selection =
|
||||
if let Some(test_all_results) = app.data.sonarr_data.indexer_test_all_results.as_ref() {
|
||||
test_all_results.current_selection().clone()
|
||||
@@ -77,7 +75,7 @@ fn draw_test_all_indexers_test_results(f: &mut Frame<'_>, app: &mut App<'_>, are
|
||||
test_results_row_mapping,
|
||||
)
|
||||
.block(borderless_block())
|
||||
.loading(app.is_loading)
|
||||
.loading(is_loading)
|
||||
.footer(Some(help_footer))
|
||||
.footer_alignment(Alignment::Center)
|
||||
.margin(1)
|
||||
|
||||
Reference in New Issue
Block a user