feat: Pagination support for jumping 20 items at a time in all table views [#45]

This commit is contained in:
2025-08-08 17:04:28 -06:00
parent 345bb8ce03
commit e96af7410e
11 changed files with 362 additions and 7 deletions
+26
View File
@@ -44,6 +44,8 @@ macro_rules! handle_table_events {
match $self.key {
_ if $crate::matches_key!(up, $self.key, $self.ignore_special_keys()) => $self.[<handle_ $name _table_scroll_up>](config),
_ if $crate::matches_key!(down, $self.key, $self.ignore_special_keys()) => $self.[<handle_ $name _table_scroll_down>](config),
_ if $crate::matches_key!(pg_up, $self.key, $self.ignore_special_keys()) => $self.[<handle_ $name _table_page_up>](config),
_ if $crate::matches_key!(pg_down, $self.key, $self.ignore_special_keys()) => $self.[<handle_ $name _table_page_down>](config),
_ if $crate::matches_key!(home, $self.key) => $self.[<handle_ $name _table_home>](config),
_ if $crate::matches_key!(end, $self.key) => $self.[<handle_ $name _table_end>](config),
_ if $crate::matches_key!(left, $self.key, $self.ignore_special_keys())
@@ -116,6 +118,30 @@ macro_rules! handle_table_events {
}
}
fn [<handle_ $name _table_page_down>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
use $crate::models::Paginated;
match $self.app.get_current_route() {
_ if config.table_block == $self.app.get_current_route() => {
$table.page_down();
true
}
_ => false,
}
}
fn [<handle_ $name _table_page_up>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
use $crate::models::Paginated;
match $self.app.get_current_route() {
_ if config.table_block == $self.app.get_current_route() => {
$table.page_up();
true
}
_ => false,
}
}
fn [<handle_ $name _table_home>](&mut $self, config: $crate::handlers::table_handler::TableHandlingConfig<$row>) -> bool {
use $crate::models::Scrollable;
+42
View File
@@ -429,6 +429,48 @@ mod tests {
}
}
mod test_handle_pagination_scroll {
use super::*;
use crate::handlers::table_handler::table_handler_tests::tests::TableHandlerUnit;
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
use pretty_assertions::assert_str_eq;
use rstest::rstest;
use std::iter;
#[rstest]
fn test_table_pagination_scroll(
#[values(DEFAULT_KEYBINDINGS.pg_up.key, DEFAULT_KEYBINDINGS.pg_down.key)] key: Key,
) {
let mut app = App::test_default();
app.push_navigation_stack(ActiveRadarrBlock::Movies.into());
let mut curr = 0;
let movies_vec = iter::repeat_with(|| {
let tmp = curr;
curr += 1;
Movie {
title: format!("Test {tmp}").into(),
..Movie::default()
}
})
.take(100)
.collect();
app.data.radarr_data.movies.set_items(movies_vec);
TableHandlerUnit::new(key, &mut app, ActiveRadarrBlock::Movies, None).handle();
if key == Key::PgUp {
assert_str_eq!(
app.data.radarr_data.movies.current_selection().title.text,
"Test 79"
);
} else {
assert_str_eq!(
app.data.radarr_data.movies.current_selection().title.text,
"Test 20"
);
}
}
}
mod test_handle_left_right_action {
use pretty_assertions::assert_eq;
use std::sync::atomic::Ordering::SeqCst;