From b73adf45f8055ef5339c2c82fd80671e81b4e97d Mon Sep 17 00:00:00 2001 From: Vinod J M Date: Mon, 31 Oct 2022 22:49:02 +0530 Subject: [PATCH] v0.10-frontend2 --- backend/api/src/lib.rs | 36 +++++++++++++++++++++++++++++++++--- frontend/css/index.css | 41 +++++++++++++++++++++++++++++++++++++++++ frontend/index.html | 5 +++-- frontend/src/main.rs | 29 +++++++++++++++++++++++++---- 4 files changed, 102 insertions(+), 9 deletions(-) create mode 100644 frontend/css/index.css diff --git a/backend/api/src/lib.rs b/backend/api/src/lib.rs index f9251ef..bec9478 100644 --- a/backend/api/src/lib.rs +++ b/backend/api/src/lib.rs @@ -71,6 +71,18 @@ struct Books { docs: Vec, } + +#[derive(Deserialize, Serialize, Debug)] +struct BookPageOL { + description: Option, +} + +#[derive(Deserialize, Serialize, Debug)] +struct DescriptionOL { + value: Option, +} + + impl Books { fn set_all_cover_urls(&mut self) { for book in self.docs.iter_mut() { @@ -85,6 +97,23 @@ impl Books { } } } + async fn set_all_descriptions(&mut self) { + for book in self.docs.iter_mut() { + let query = format!("https://openlibrary.org/{}.json", book.key); + let res = reqwest::get(query).await.expect("Unable to request"); + let resjson = res.json::().await.expect("Unable to return value"); + let description = resjson.description; + match description { + Some(description) => { + match description.value { + Some(value) => book.description = Some(value), + None => (), + } + } + None => (), + } + } + } } // Setup the command line interface with clap. @@ -170,11 +199,12 @@ async fn search_openlibrary( let query = format!("https://openlibrary.org/search.json?q={}", search); let res = reqwest::get(query).await.expect("Unable to request"); let mut resjson = res.json::().await.expect("Unable to return value"); - resjson.docs.truncate(10); + resjson.docs.truncate(12); resjson.set_all_cover_urls(); +// resjson.set_all_descriptions().await; print!("Search token {:?}\n", search); -let mut vec = Vec::with_capacity(10); - for i in 0..10 as usize { +let mut vec = Vec::with_capacity(12); + for i in 0..12 as usize { let doc = resjson.docs[i].clone(); vec.push( BookUI{ diff --git a/frontend/css/index.css b/frontend/css/index.css new file mode 100644 index 0000000..293d6d9 --- /dev/null +++ b/frontend/css/index.css @@ -0,0 +1,41 @@ +* { + box-sizing: border-box; +} + +body { + font-family: Arial, Helvetica, sans-serif; +} + +/* Float four columns side by side */ +.column { + float: left; + width: 25%; + padding: 0 10px; +} + +/* Remove extra left and right margins, due to padding in columns */ +.row {margin: 0 -5px;} + +/* Clear floats after the columns */ +.row:after { + content: ""; + display: table; + clear: both; +} + +/* Style the counter cards */ +.card { + box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); /* this adds the "card" effect */ + padding: 16px; + text-align: center; + background-color: #f1f1f1; +} + +/* Responsive columns - one column layout (vertical) on small screens */ +@media screen and (max-width: 600px) { + .column { + width: 100%; + display: block; + margin-bottom: 20px; + } +} diff --git a/frontend/index.html b/frontend/index.html index f30bf99..a9212bd 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -3,8 +3,9 @@ - Sycamore App + + Book Manager - loading... + diff --git a/frontend/src/main.rs b/frontend/src/main.rs index 8572098..e56ce14 100644 --- a/frontend/src/main.rs +++ b/frontend/src/main.rs @@ -214,7 +214,7 @@ async fn ListOL(cx: Scope<'_>) -> View { p { (if *app_state.openlibrary.get() == true { view!{ cx, - ul { + div(class="row") { Keyed( iterable=docs, view=move |cx, x| view! { cx, @@ -243,10 +243,12 @@ pub fn BookOL(cx: Scope, bookitem: BookUIProp) -> View { }; view! { cx, - li{ + div(class="column"){ + div(class="card"){ (format!("{:?}",bookdisp)) button(class="add", on:click=handle_add){ "+" } } + } } } @@ -254,7 +256,6 @@ pub fn BookOL(cx: Scope, bookitem: BookUIProp) -> View { #[component] async fn AddingUI(cx: Scope<'_>) -> View { let app_state = use_context::(cx); - let inp_title = create_signal(cx, (*app_state.addingbook.get()).clone().title); let inp_olkey = create_signal(cx, (*app_state.addingbook.get()).clone().open_library_key.unwrap_or("".to_string())); let inp_editioncount = create_signal(cx, (*app_state.addingbook.get()).clone().edition_count.unwrap_or(0).to_string()); @@ -272,7 +273,27 @@ let inp_place = create_signal(cx, (*app_state.addingbook.get()).clone().place.un let inp_subject = create_signal(cx, (*app_state.addingbook.get()).clone().subject.unwrap_or(vec!["".to_string()]).join(", ")); let inp_time = create_signal(cx, (*app_state.addingbook.get()).clone().time.unwrap_or(vec!["".to_string()]).join(", ")); let inp_isbn = create_signal(cx, (*app_state.addingbook.get()).clone().isbn.unwrap_or(vec!["".to_string()]).join(", ")); - + create_effect(cx, || { + + info!("{:?}",*app_state.addingbook.get()); +inp_title.set((*app_state.addingbook.get()).clone().title); +inp_olkey.set((*app_state.addingbook.get()).clone().open_library_key.unwrap_or("".to_string())); +inp_editioncount.set((*app_state.addingbook.get()).clone().edition_count.unwrap_or(0).to_string()); +inp_publishyear.set((*app_state.addingbook.get()).clone().first_publish_year.unwrap_or(0).to_string()); +inp_medianpage.set((*app_state.addingbook.get()).clone().median_page_count.unwrap_or(0).to_string()); +inp_goodread.set((*app_state.addingbook.get()).clone().goodread_id.unwrap_or("".to_string())); +inp_desc.set((*app_state.addingbook.get()).clone().description.unwrap_or("".to_string())); +inp_cover.set((*app_state.addingbook.get()).clone().cover.unwrap_or("".to_string())); +inp_location.set((*app_state.addingbook.get()).clone().location.unwrap_or("".to_string())); +inp_rating.set((*app_state.addingbook.get()).clone().location.unwrap_or("".to_string())); +inp_comments.set((*app_state.addingbook.get()).clone().comments.unwrap_or("".to_string())); +inp_author.set((*app_state.addingbook.get()).clone().author_name.unwrap_or(vec!["".to_string()]).join(", ")); + inp_person.set((*app_state.addingbook.get()).clone().person.unwrap_or(vec!["".to_string()]).join(", ")); + inp_place.set((*app_state.addingbook.get()).clone().place.unwrap_or(vec!["".to_string()]).join(", ")); + inp_subject.set((*app_state.addingbook.get()).clone().subject.unwrap_or(vec!["".to_string()]).join(", ")); + inp_time.set((*app_state.addingbook.get()).clone().time.unwrap_or(vec!["".to_string()]).join(", ")); + inp_isbn.set((*app_state.addingbook.get()).clone().isbn.unwrap_or(vec!["".to_string()]).join(", ")); +}); let handle_add = |_| { info!("Adding book"); let authors: Vec = (*inp_author.get()).clone().split(",").map(str::to_string).collect::>();