v0.15-WORKINGV3

This commit is contained in:
2022-12-04 12:26:02 +05:30
parent 32fb36623b
commit c8fba74480
4 changed files with 103 additions and 57 deletions

View File

@@ -12,6 +12,7 @@ use wasm_bindgen::JsCast;
use web_sys::{Event, HtmlInputElement, KeyboardEvent}; // 0.3.5
use dotenv_codegen::dotenv;
use itertools::Itertools;
//use gloo_timers::future::TimeoutFuture;
//#[macro_use]
//extern crate dotenv_codegen;
@@ -63,6 +64,11 @@ pub struct AppState {
pub addingbook: RcSignal<BookUI>,
pub displayingbook: RcSignal<BookUI>,
pub refreshing: RcSignal<bool>,
pub apibook: RcSignal<BookUI>,
pub updatingrequest: RcSignal<bool>,
pub addingrequest: RcSignal<bool>,
pub deleteid: RcSignal<i32>,
pub deleterequest: RcSignal<bool>
}
#[derive(Route)]
@@ -227,8 +233,9 @@ pub fn Header<G: Html>(cx: Scope) -> View<G> {
};
let click_addbook = |_| {
app_state.adding.set(true);
app_state.addingbook.set(BookUI::default());
app_state.adding.set(true);
app_state.updating.set(false);
app_state.addingbook.set(BookUI::default());
};
@@ -257,6 +264,7 @@ pub fn Header<G: Html>(cx: Scope) -> View<G> {
spawn_local(async move {
let _temp = add_books_isbns(task).await.unwrap();
});
}
};
@@ -311,14 +319,17 @@ async fn ListDB<G: Html>(cx: Scope<'_>) -> View<G> {
app_state.openlibrary.track();
app_state.internalsearch.track();
app_state.refreshing.track();
info!(
"The state changed. New value: {}",
app_state.search.get(),
);
//let tempb = app_state.books.get();
//spawn_local( async move { info!(
// "The state changed. Old value: {:?}",
// app_state.books.get()
//)});
if *app_state.openlibrary.get() == false {
app_state.refreshing.set(false);
if *app_state.refreshing.get() == true {
app_state.refreshing.set(false);
//TimeoutFuture::new(1000).await;
}
if *app_state.internalsearch.get() == false {
spawn_local(async move {
@@ -358,6 +369,8 @@ async fn ListDB<G: Html>(cx: Scope<'_>) -> View<G> {
});
}
}
info!("List Refreshing Done");
});
let docs = create_memo(cx, || app_state.books.get().iter().cloned().collect::<Vec<_>>());
@@ -393,23 +406,33 @@ pub fn BookDB<G: Html>(cx: Scope, bookitem: BookUIProp) -> View<G> {
let locdesc = bookitem.bookitem.clone().description.unwrap_or("".to_string());
let locloc = bookitem.bookitem.clone().location.unwrap_or("".to_string());
//let locref = create_rc_signal(false);
let coverurl = bookdisplay.clone().cover.clone().unwrap_or("None".to_string());
let handle_delete = move |_| {
spawn_local(async move {
let temp = delete_book(bookdelete.id).await.unwrap();
println!("{}",temp.status());
});
app_state.refreshing.set(true);
app_state.deleteid.set(bookdelete.id);
app_state.deleterequest.set(true);
};
create_effect(cx, || {
let app_state = app_state.clone();
if *app_state.deleterequest.get() == true {
spawn_local(async move {
let temp = delete_book(*app_state.deleteid.get()).await.unwrap();
println!("{}",temp.status());
app_state.refreshing.set(true);
});
}
app_state.deleterequest.set(false);
});
let handle_update = move |_| {
app_state.adding.set(false);
app_state.updating.set(true);
app_state.addingbook.set(bookupdate.clone());
app_state.refreshing.set(true);
};
let handle_display = move |_| {
@@ -612,28 +635,40 @@ info!("Adding book");
time: Some(times),
isbn: Some(isbns),
};
if *app_state.updating.get() == false {
spawn_local(async move {
let temp = add_book(record).await.unwrap();
println!("{}",temp.status());
});
} else {
spawn_local(async move {
let temp = update_book(record).await.unwrap();
println!("{}",temp.status());
});
if *app_state.adding.get() == true {
app_state.addingrequest.set(true);
} else if *app_state.updating.get() == true{
app_state.updatingrequest.set(true);
}
app_state.apibook.set(record);
app_state.addingbook.set(BookUI::default());
app_state.updating.set(false);
app_state.adding.set(false);
//app_state.books.set(vec![BookUI::default()]);
app_state.refreshing.set(true);
};
create_effect(cx, || {
let app_state = app_state.clone();
let record = (*app_state.apibook.get()).clone();
if *app_state.addingrequest.get() == true {
spawn_local(async move {
let temp = add_book(record).await.unwrap();
info!("Adding Done{}",temp.status());
app_state.refreshing.set(true);
app_state.addingrequest.set(false);
});
} else if *app_state.updatingrequest.get() == true{
spawn_local(async move {
let temp = update_book(record).await.unwrap();
info!("Updating Done{}",temp.status());
app_state.refreshing.set(true);
app_state.updatingrequest.set(false);
});
}
});
create_effect(cx, || {
if *app_state.updating.get() == true || *app_state.adding.get() == true {
@@ -956,6 +991,11 @@ fn App<G: Html>(cx: Scope) -> View<G> {
displaying: create_rc_signal(bool::default()),
displayingbook: create_rc_signal(BookUI::default()),
refreshing: create_rc_signal(bool::default()),
apibook: create_rc_signal(BookUI::default()),
updatingrequest: create_rc_signal(bool::default()),
addingrequest: create_rc_signal(bool::default()),
deleteid: create_rc_signal(-1),
deleterequest: create_rc_signal(bool::default()),
};
provide_context(cx, app_state);
view! {