add functionnal front
add some basics logs, just to debug
This commit is contained in:
parent
b3d58a4a19
commit
1260319ceb
2 changed files with 45 additions and 17 deletions
front
|
@ -5,5 +5,7 @@ edition = "2024"
|
|||
|
||||
[dependencies]
|
||||
leptos = { version = "0.7.8", features = ["csr"] }
|
||||
log = "0.4.27"
|
||||
reqwest = { version = "0.12.15", features = ["json"] }
|
||||
serde = { version = "1.0.219", features = ["serde_derive"] }
|
||||
wasm-logger = "0.2.0"
|
||||
|
|
|
@ -2,23 +2,33 @@ use leptos::ev::*;
|
|||
use leptos::html;
|
||||
use leptos::prelude::*;
|
||||
use serde::Deserialize;
|
||||
use log::info;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
struct InfoVideo {
|
||||
video: String,
|
||||
timecode: Vec<i32>,
|
||||
}
|
||||
|
||||
async fn get_videos(word: String) -> Result<Vec<InfoVideo>, reqwest::Error>{
|
||||
let mut s = String::from("https://localhost:8300/search?=");
|
||||
s.push_str(&word);
|
||||
reqwest::get(s).await?.json::<Vec<InfoVideo>>().await
|
||||
if word.is_empty() {
|
||||
Ok(Vec::new())
|
||||
} else {
|
||||
let mut s = String::from("http://localhost:8300/search?query=");
|
||||
s.push_str(&word);
|
||||
let ret = reqwest::get(s).await?.json::<Vec<InfoVideo>>().await;
|
||||
info!("coucou {:?}", ret);
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
let (name, name_set) = signal(String::from(""));
|
||||
let input_element: NodeRef<html::Input> = NodeRef::new();
|
||||
let list_videos: Vec<InfoVideo> = Vec::new();
|
||||
|
||||
let aync_videos = LocalResource::new(move || get_videos(name.get()));
|
||||
|
||||
let on_submit = move |ev: SubmitEvent| {
|
||||
ev.prevent_default();
|
||||
|
@ -27,25 +37,41 @@ pub fn App() -> impl IntoView {
|
|||
name_set.set(value);
|
||||
};
|
||||
|
||||
view! {
|
||||
<Show
|
||||
when=move || { name.get().is_empty() }
|
||||
fallback=move || view! {
|
||||
<p>"Oh, blin"</p>
|
||||
<p>{name}</p>
|
||||
let truc = move || {
|
||||
if let Some(r) = aync_videos.read().as_ref() {
|
||||
info!("meh");
|
||||
if let Ok(v) = r.as_ref() {
|
||||
info!("pouet");
|
||||
v.iter().map(|n| view! { <li>{n.video.clone()}</li> }).collect_view()
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
};
|
||||
|
||||
view! {
|
||||
<form on:submit=on_submit>
|
||||
<input type="text"
|
||||
value=name
|
||||
node_ref=input_element
|
||||
/>
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
|
||||
<Show
|
||||
when=move || { !truc().is_empty() }
|
||||
>
|
||||
<form on:submit=on_submit>
|
||||
<input type="text"
|
||||
value=name
|
||||
node_ref=input_element
|
||||
/>
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
<p>F E L I C I T A T I O N</p>
|
||||
<ul>
|
||||
{truc}
|
||||
</ul>
|
||||
</Show>
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
wasm_logger::init(wasm_logger::Config::default());
|
||||
leptos::mount::mount_to_body(App)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue