v0.11-paginationP1
This commit is contained in:
@@ -38,6 +38,11 @@ pub struct BookUIProp {
|
||||
bookitem: BookUI,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
struct PaginatedBookUIList {
|
||||
num_pages: u32,
|
||||
books: Vec<BookUI>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct AppState {
|
||||
@@ -74,15 +79,15 @@ async fn add_book(record: BookUI) -> Result<reqwasm::http::Response, reqwasm::Er
|
||||
|
||||
async fn delete_book(id: i32) -> Result<reqwasm::http::Response, reqwasm::Error> {
|
||||
let url = format!("http://localhost:8081/api/delete/{}", id);
|
||||
let resp = Request::post(&url).send().await?;
|
||||
let resp = Request::get(&url).send().await?;
|
||||
Ok(resp)
|
||||
}
|
||||
|
||||
async fn list_books() -> Result<Vec<BookUI>, reqwasm::Error> {
|
||||
let url = format!("http://localhost:8081/api/list");
|
||||
let resp = Request::post(&url).send().await?;
|
||||
async fn list_books(page: u32) -> Result<PaginatedBookUIList, reqwasm::Error> {
|
||||
let url = format!("http://localhost:8081/api/list?page={}",page);
|
||||
let resp = Request::get(&url).send().await?;
|
||||
println!("Fetching books\n");
|
||||
let body = resp.json::<Vec<BookUI>>().await?;
|
||||
let body = resp.json::<PaginatedBookUIList>().await?;
|
||||
Ok(body)
|
||||
}
|
||||
|
||||
@@ -140,9 +145,9 @@ async fn ListDB<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
if *app_state.openlibrary.get() == false {
|
||||
spawn_local(async move {
|
||||
app_state.books.set(
|
||||
list_books()
|
||||
list_books(1)
|
||||
.await
|
||||
.unwrap(),
|
||||
.unwrap().books,
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user