diff --git a/frontend/src/main.rs b/frontend/src/main.rs index 66e276d..b0a11b6 100644 --- a/frontend/src/main.rs +++ b/frontend/src/main.rs @@ -6,11 +6,10 @@ use sycamore::futures::spawn_local; use sycamore::prelude::*; use sycamore::suspense::Suspense; use sycamore_router::Route; -//use tokio; use wasm_bindgen::JsCast; 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 { key: String, title: String, @@ -92,28 +91,16 @@ pub fn Header(cx: Scope) -> View { on:keyup=handle_submit, ) } - //VisitsCount {} } } #[component] async fn VisitsCount(cx: Scope<'_>) -> View { let app_state = use_context::(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, || { //info!( // "The state changed. New value: {} {}", // app_state.search.get(), - // app_state.books.get().num_found //); let app_state = app_state.clone(); app_state.search.track(); @@ -125,15 +112,25 @@ async fn VisitsCount(cx: Scope<'_>) -> View { ) }); }); - - // let lbooks = fetch_books("lord of the rings".to_string()).await.unwrap(); + let docs = create_memo(cx, || app_state.books.get().docs.clone()); + //let docs = create_signal(cx, vec![1, 2]); view! {cx, p { (if !app_state.search.get().is_empty() { - view!{cx,span {(app_state.books.get().num_found)} } - }else { + view!{ cx, + span {(app_state.books.get().num_found)} + ul { + Indexed( + iterable=docs, + view=|cx, x| view! { cx, + li { (format!("{:?}",x)) } + }) + } + } + } + else { view! { cx, span { "World" } } - }) + }) } } }