From 72622032ad7a3187e35ce244a358a8cc54263e00 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Wed, 12 Apr 2023 07:34:30 -0700 Subject: [PATCH] web: add pagination to bottom of search results --- web/src/lib.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/web/src/lib.rs b/web/src/lib.rs index 0094179..7a82aaa 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -8,7 +8,7 @@ use std::{ }; use itertools::Itertools; -use log::{debug, error, info, warn, Level}; +use log::{debug, error, info, Level}; use notmuch::{Content, Part, Thread, ThreadNode, ThreadSet}; use seed::{prelude::*, *}; use serde::de::Deserialize; @@ -512,7 +512,8 @@ fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult div![ h1!["Search results"], view_search_pager(first, summaries.len(), search_results.total), - rows + rows, + view_search_pager(first, summaries.len(), search_results.total) ] } @@ -564,26 +565,35 @@ fn view_search_results(query: &str, search_results: &shared::SearchResult) -> No th![C!["date"], "Date"] ]], tbody![rows] - ] + ], + view_search_pager(first, summaries.len(), search_results.total) ] } -fn view_search_pager(page: usize, count: usize, total: usize) -> Node { +fn view_search_pager(start: usize, count: usize, total: usize) -> Node { + let is_first = start <= 0; + let is_last = (start + SEARCH_RESULTS_PER_PAGE) >= total; nav![ C!["pagination"], a![ - C!["pagination-previous", "button"], + C![ + "pagination-previous", + "button", + IF!(is_first => "is-static"), + IF!(is_first => "is-info"), + ], "<", ev(Ev::Click, |_| Msg::PreviousPage) ], a![ - C!["pagination-next", "button"], + C!["pagination-next", "button", IF!(is_last => "is-static")], + IF!(is_last => attrs!{ At::Disabled=>true }), ">", ev(Ev::Click, |_| Msg::NextPage) ], ul![ C!["pagination-list"], - li![format!("{} - {} of {}", page, page + count, total)], + li![format!("{} - {} of {}", start, start + count, total)], ], ] }