This commit is contained in:
2022-10-10 23:29:21 +05:30
parent 9351d61f70
commit 44f9a8b15f

View File

@@ -6,11 +6,10 @@ use sycamore::futures::spawn_local;
use sycamore::prelude::*; use sycamore::prelude::*;
use sycamore::suspense::Suspense; use sycamore::suspense::Suspense;
use sycamore_router::Route; use sycamore_router::Route;
//use tokio;
use wasm_bindgen::JsCast; use wasm_bindgen::JsCast;
use web_sys::{Event, HtmlInputElement, KeyboardEvent}; // 0.3.5 use web_sys::{Event, HtmlInputElement, KeyboardEvent}; // 0.3.5
#[derive(Deserialize, Serialize, Debug, Default)] #[derive(Deserialize, Serialize, Debug, Default, Clone, PartialEq, Hash, Eq)]
pub struct Docs { pub struct Docs {
key: String, key: String,
title: String, title: String,
@@ -92,28 +91,16 @@ pub fn Header<G: Html>(cx: Scope) -> View<G> {
on:keyup=handle_submit, on:keyup=handle_submit,
) )
} }
//VisitsCount {}
} }
} }
#[component] #[component]
async fn VisitsCount<G: Html>(cx: Scope<'_>) -> View<G> { async fn VisitsCount<G: Html>(cx: Scope<'_>) -> View<G> {
let app_state = use_context::<AppState>(cx); let app_state = use_context::<AppState>(cx);
/* create_effect(cx, || {
info!(
"The state changed. New value: {} {}",
app_state.search.get(),
app_state.books.get().num_found
)
});
*/
// app_state.set_books(search.to_string()).await;
//app_state.set_books("Lord of the rings".to_string()).await;
create_effect(cx, || { create_effect(cx, || {
//info!( //info!(
// "The state changed. New value: {} {}", // "The state changed. New value: {} {}",
// app_state.search.get(), // app_state.search.get(),
// app_state.books.get().num_found
//); //);
let app_state = app_state.clone(); let app_state = app_state.clone();
app_state.search.track(); app_state.search.track();
@@ -125,13 +112,23 @@ async fn VisitsCount<G: Html>(cx: Scope<'_>) -> View<G> {
) )
}); });
}); });
let docs = create_memo(cx, || app_state.books.get().docs.clone());
// let lbooks = fetch_books("lord of the rings".to_string()).await.unwrap(); //let docs = create_signal(cx, vec![1, 2]);
view! {cx, view! {cx,
p { p {
(if !app_state.search.get().is_empty() { (if !app_state.search.get().is_empty() {
view!{cx,span {(app_state.books.get().num_found)} } view!{ cx,
}else { span {(app_state.books.get().num_found)}
ul {
Indexed(
iterable=docs,
view=|cx, x| view! { cx,
li { (format!("{:?}",x)) }
})
}
}
}
else {
view! { cx, span { "World" } } view! { cx, span { "World" } }
}) })
} }