v0.10-frontend2

This commit is contained in:
2022-10-31 22:49:02 +05:30
parent 30cd957b00
commit b73adf45f8
4 changed files with 102 additions and 9 deletions

View File

@@ -71,6 +71,18 @@ struct Books {
docs: Vec<Docs>,
}
#[derive(Deserialize, Serialize, Debug)]
struct BookPageOL {
description: Option<DescriptionOL>,
}
#[derive(Deserialize, Serialize, Debug)]
struct DescriptionOL {
value: Option<String>,
}
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::<BookPageOL>().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::<Books>().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{

41
frontend/css/index.css Normal file
View File

@@ -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;
}
}

View File

@@ -3,8 +3,9 @@
<head>
<meta charset="utf-8" />
<link rel="shortcut icon"type="image/x-icon" href="data:image/x-icon;,">
<title>Sycamore App</title>
<link data-trunk rel="css" href="css/index.css"/>
<title>Book Manager</title>
<base href="/"/>
</head>
<body>loading...</body>
<body></body>
</html>

View File

@@ -214,7 +214,7 @@ async fn ListOL<G: Html>(cx: Scope<'_>) -> View<G> {
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<G: Html>(cx: Scope, bookitem: BookUIProp) -> View<G> {
};
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<G: Html>(cx: Scope, bookitem: BookUIProp) -> View<G> {
#[component]
async fn AddingUI<G: Html>(cx: Scope<'_>) -> View<G> {
let app_state = use_context::<AppState>(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<String> = (*inp_author.get()).clone().split(",").map(str::to_string).collect::<Vec<String>>();