use std::sync::Arc; use calibre_db::data::pagination::SortOrder; use poem::{ handler, web::{Data, Html, Path}, }; use crate::{app_state::AppState, data::book::Book}; use super::paginated; #[handler] pub async fn handler_init(state: Data<&Arc>) -> Result, poem::Error> { books(&state, None, &SortOrder::ASC) } #[handler] pub async fn handler( Path((cursor, sort_order)): Path<(String, SortOrder)>, state: Data<&Arc>, ) -> Result, poem::Error> { books(&state, Some(&cursor), &sort_order) } fn books( state: &Arc, cursor: Option<&str>, sort_order: &SortOrder, ) -> Result, poem::Error> { paginated::render( "books", || { state.calibre.books(25, cursor, sort_order).map(|x| { x.iter() .filter_map(|y| Book::full_book(y, &state)) .collect() }) }, |book| book.sort.clone(), |cursor| state.calibre.has_previous_books(cursor), |cursor| state.calibre.has_more_books(cursor), ) }