First import

This commit is contained in:
2022-04-05 23:00:18 +02:00
commit f7aa21e338
46 changed files with 1621 additions and 0 deletions

View File

@@ -0,0 +1 @@
pub mod object;

View File

@@ -0,0 +1,23 @@
use {{crate_name}};
use uikit_rs as uk;
use yew::{classes, function_component, html, Properties};
#[derive(Properties, PartialEq)]
pub struct ObjectProps {
#[prop_or_default]
pub object: Option<{{crate_name}}::Object>,
}
#[function_component(Object)]
pub fn object(ObjectProps { object }: &ObjectProps) -> Html {
html! {
<span class={classes!(uk::Text::Meta)}>
{
match object {
Some(obj) => format!("object: {}", obj.name ),
None => "No object".to_string()
}
}
</span>
}
}

46
template/web/src/lib.rs Normal file
View File

@@ -0,0 +1,46 @@
use components::object;
use ::{{crate_name}}::Object;
use reqwasm::http::Request;
use uikit_rs as uk;
use wasm_bindgen::prelude::*;
use yew::prelude::*;
mod components;
#[wasm_bindgen(module = "/js/api.js")]
extern "C" {
fn get_api_base_url() -> String;
}
#[function_component(App)]
pub fn app() -> Html {
let object = use_state(|| None);
{
let object = object.clone();
use_effect_with_deps(
move |_| {
wasm_bindgen_futures::spawn_local(async move {
let fetched_object: Object =
Request::get(&format!("{}/hello", get_api_base_url()))
.send()
.await
.unwrap() // TODO
.json()
.await
.unwrap(); // TODO
object.set(Some(fetched_object));
});
|| ()
},
(),
);
}
html! {
<uk::Section style={uk::SectionStyle::Default}>
<uk::Container size={uk::ContainerSize::Small}>
<object::Object object={(*object).clone()} />
</uk::Container>
</uk::Section>
}
}

5
template/web/src/main.rs Normal file
View File

@@ -0,0 +1,5 @@
use {{crate_name}}_web::App;
fn main() {
yew::start_app::<App>();
}