Refactored tables and loading blocks to use the new dedicated widgets for Tables and Loading blocks

This commit is contained in:
2024-02-10 19:23:19 -07:00
parent 68de986c48
commit 51b789fd0f
19 changed files with 1174 additions and 1150 deletions
+66 -67
View File
@@ -8,7 +8,8 @@ use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, DOWNLO
use crate::models::{HorizontallyScrollableText, Route};
use crate::ui::styles::ManagarrStyle;
use crate::ui::utils::{get_width_from_percentage, layout_block_top_border};
use crate::ui::{draw_prompt_box, draw_prompt_popup_over, draw_table, DrawUi, TableProps};
use crate::ui::widgets::managarr_table::ManagarrTable;
use crate::ui::{draw_prompt_box, draw_prompt_popup_over, DrawUi};
use crate::utils::convert_to_gb;
#[cfg(test)]
@@ -48,76 +49,74 @@ fn draw_downloads(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
} else {
app.data.radarr_data.downloads.current_selection().clone()
};
let downloads_table_footer = app
.data
.radarr_data
.main_tabs
.get_active_tab_contextual_help();
draw_table(
f,
area,
layout_block_top_border(),
TableProps {
content: Some(&mut app.data.radarr_data.downloads),
wrapped_content: None,
table_headers: vec![
"Title",
"Percent Complete",
"Size",
"Output Path",
"Indexer",
"Download Client",
],
constraints: vec![
Constraint::Percentage(30),
Constraint::Percentage(11),
Constraint::Percentage(11),
Constraint::Percentage(18),
Constraint::Percentage(17),
Constraint::Percentage(13),
],
help: app
.data
.radarr_data
.main_tabs
.get_active_tab_contextual_help(),
},
|download_record| {
let DownloadRecord {
title,
size,
sizeleft,
download_client,
indexer,
output_path,
..
} = download_record;
let downloads_row_mapping = |download_record: &DownloadRecord| {
let DownloadRecord {
title,
size,
sizeleft,
download_client,
indexer,
output_path,
..
} = download_record;
if output_path.is_some() {
output_path.as_ref().unwrap().scroll_left_or_reset(
get_width_from_percentage(area, 18),
current_selection == *download_record,
app.tick_count % app.ticks_until_scroll == 0,
);
}
if output_path.is_some() {
output_path.as_ref().unwrap().scroll_left_or_reset(
get_width_from_percentage(area, 18),
current_selection == *download_record,
app.tick_count % app.ticks_until_scroll == 0,
);
}
let percent = 1f64 - (*sizeleft as f64 / *size as f64);
let file_size: f64 = convert_to_gb(*size);
let percent = 1f64 - (*sizeleft as f64 / *size as f64);
let file_size: f64 = convert_to_gb(*size);
Row::new(vec![
Cell::from(title.to_owned()),
Cell::from(format!("{:.0}%", percent * 100.0)),
Cell::from(format!("{file_size:.2} GB")),
Cell::from(
output_path
.as_ref()
.unwrap_or(&HorizontallyScrollableText::default())
.to_string(),
),
Cell::from(indexer.to_owned()),
Cell::from(download_client.to_owned()),
])
.primary()
},
app.is_loading,
true,
);
Row::new(vec![
Cell::from(title.to_owned()),
Cell::from(format!("{:.0}%", percent * 100.0)),
Cell::from(format!("{file_size:.2} GB")),
Cell::from(
output_path
.as_ref()
.unwrap_or(&HorizontallyScrollableText::default())
.to_string(),
),
Cell::from(indexer.to_owned()),
Cell::from(download_client.to_owned()),
])
.primary()
};
let downloads_table = ManagarrTable::new(
Some(&mut app.data.radarr_data.downloads),
downloads_row_mapping,
)
.block(layout_block_top_border())
.loading(app.is_loading)
.footer(downloads_table_footer)
.headers([
"Title",
"Percent Complete",
"Size",
"Output Path",
"Indexer",
"Download Client",
])
.constraints([
Constraint::Percentage(30),
Constraint::Percentage(11),
Constraint::Percentage(11),
Constraint::Percentage(18),
Constraint::Percentage(17),
Constraint::Percentage(13),
]);
f.render_widget(downloads_table, area);
}
fn draw_delete_download_prompt(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {