Skip to content

Commit

Permalink
make total_size optional in pagination
Browse files Browse the repository at this point in the history
as off 2024-04-09, the artciles by sectoion endpoint might not return the total size if pagination isn't wanted
  • Loading branch information
luis.scheurenbrand committed Apr 10, 2024
1 parent 11fae52 commit 9785c7f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/api/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Articles {
#[derive(Deserialize)]
pub struct Pagination {
pub size: u32,
pub total_size: u32,
pub total_size: Option<u32>,
pub orderby: String,
}

Expand Down
4 changes: 2 additions & 2 deletions src/routes/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn render_articles(
.as_ref()
.map(|a| a.len() as u32)
.unwrap_or(0);
let total = articles.pagination.total_size;
let total = articles.pagination.total_size.unwrap_or(0);
let (has_prev, has_next) = (offset > 0, offset + count < total);
let prev_page = if has_prev {
let offset = offset.saturating_sub(steps);
Expand Down Expand Up @@ -122,7 +122,7 @@ fn render_articles(
li { a href=(&article.canonical_url) { (&article.title) } }
}
}
@if total != 0 {
@if has_prev || has_next {
div.nav {
a href=[prev_page] { "<" }
((offset + 1)) " to " ((offset + count)) " of " (total)
Expand Down

0 comments on commit 9785c7f

Please sign in to comment.