User Authentication and Other fixes #1
@@ -165,8 +165,12 @@ async fn fetch_books(search: String) -> Result<Vec<BookUI>, reqwasm::Error> {
|
||||
let url = format!("{}/api/search_openlibrary?search={}", backend_url, search);
|
||||
let resp = Request::get(&url).send().await?;
|
||||
println!("Fetching books\n");
|
||||
let body = resp.json::<Vec<BookUI>>().await?;
|
||||
Ok(body)
|
||||
if resp.status() == 200 {
|
||||
let body = resp.json::<Vec<BookUI>>().await?;
|
||||
Ok(body)
|
||||
} else {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
}
|
||||
|
||||
async fn search_books(
|
||||
@@ -702,6 +706,24 @@ pub fn DropDownUser<G: Html>(cx: Scope, value: StringProp) -> View<G> {
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
async fn WarningMessageBar<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
let app_state = use_context::<AppState>(cx);
|
||||
|
||||
let handle_clear_warning = move |_| {
|
||||
app_state.warningmsg.set("".to_string());
|
||||
};
|
||||
|
||||
view! {cx,
|
||||
(if *app_state.warningmsg.get() != "".to_string() {
|
||||
view!{ cx,
|
||||
div(on:click=handle_clear_warning){ (*app_state.warningmsg.get()) }
|
||||
}} else {
|
||||
view!{cx, ""}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
async fn ListDB<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
let app_state = use_context::<AppState>(cx);
|
||||
@@ -841,7 +863,11 @@ async fn ListDB<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
fetch_books(app_state.search.get().to_string())
|
||||
.await
|
||||
.unwrap(),
|
||||
)
|
||||
);
|
||||
if (*app_state.books.get()).len() == 0 {
|
||||
//let current_warning = *app_state.warningmsg.get().to_string();
|
||||
app_state.warningmsg.set(app_state.warningmsg.get().to_string() + " ** Failed to find books for " + &*app_state.search.get() + " ** ");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -863,7 +889,7 @@ async fn ListDB<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
//let csignal = csignal.clone();
|
||||
//csignal.set(true);
|
||||
let app_state2 = app_state2.clone();
|
||||
if *app_state2.scrolling.get() == false {
|
||||
if *app_state2.scrolling.get() == false && *app_state2.openlibrary.get() == false {
|
||||
if window_cl.inner_height().unwrap().as_f64().unwrap() + window_cl.scroll_y().unwrap() >= window_cl.document().unwrap().body().unwrap().offset_height().into() {
|
||||
app_state2.scrollevent.set(true);
|
||||
}
|
||||
@@ -1539,12 +1565,19 @@ async fn AddingUI<G: Html>(cx: Scope<'_>) -> View<G> {
|
||||
info!("Adding effect startedDone");
|
||||
|
||||
if *app_state.addingrequest.get() == true {
|
||||
let temp = add_book(record).await.unwrap();
|
||||
let temp = add_book(record.clone()).await.unwrap();
|
||||
if temp.status() != 200 {
|
||||
app_state.warningmsg.set(app_state.warningmsg.get().to_string() + " ** Failed to create book " + &(record.clone().title) + " ** ");
|
||||
}
|
||||
info!("Adding Done{}", temp.status());
|
||||
app_state.refreshing.set(true);
|
||||
app_state.addingrequest.set(false);
|
||||
} else if *app_state.updatingrequest.get() == true {
|
||||
let temp = update_book(record).await.unwrap();
|
||||
let temp = update_book(record.clone()).await.unwrap();
|
||||
if temp.status() != 200 {
|
||||
app_state.warningmsg.set(app_state.warningmsg.get().to_string() + " ** Failed to update book " + &(record.clone().title) + " ** ");
|
||||
|
||||
}
|
||||
info!("Updating Done{}", temp.status());
|
||||
app_state.refreshing.set(true);
|
||||
app_state.updatingrequest.set(false);
|
||||
@@ -2270,6 +2303,7 @@ fn App<G: Html>(cx: Scope) -> View<G> {
|
||||
Header {}
|
||||
MenuExpanded {}
|
||||
main(class="relative"){
|
||||
WarningMessageBar{}
|
||||
LoginScreenUI{}
|
||||
AddingUI{}
|
||||
SelectedUI{}
|
||||
|
||||
Reference in New Issue
Block a user