First import
This commit is contained in:
21
template/web/Cargo.toml
Normal file
21
template/web/Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "{{project-name}}-web"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["{{authors}}"]
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
path = "src/main.rs"
|
||||
name = "{{project-name}}-web"
|
||||
|
||||
[dependencies]
|
||||
{{project-name}} = { path = ".." }
|
||||
yew = "0.19"
|
||||
reqwasm = "0.5"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
wasm-bindgen-futures = "0.4"
|
||||
uikit-rs = { git = "https://github.com/dax/uikit-rs.git" }
|
||||
wasm-bindgen = "0.2.79"
|
||||
12
template/web/Makefile.toml
Normal file
12
template/web/Makefile.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
extend = "../Makefile.toml"
|
||||
|
||||
[tasks.build-release]
|
||||
install_crate = { crate_name = "trunk", binary = "trunk" }
|
||||
command = "trunk"
|
||||
args = ["build", "--release"]
|
||||
|
||||
[tasks.run]
|
||||
clear = true
|
||||
install_crate = { crate_name = "trunk", binary = "trunk" }
|
||||
command = "trunk"
|
||||
args = ["serve"]
|
||||
1
template/web/css/uikit.min.css
vendored
Normal file
1
template/web/css/uikit.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
13
template/web/index.html
Normal file
13
template/web/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>{{project-name | capitalize}}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="css/uikit.min.css" />
|
||||
<script src="js/uikit.min.js"></script>
|
||||
<script src="js/uikit-icons.min.js"></script>
|
||||
<link data-trunk rel="copy-dir" href="css" />
|
||||
<link data-trunk rel="copy-dir" href="js" />
|
||||
</head>
|
||||
</html>
|
||||
3
template/web/js/api.js
Normal file
3
template/web/js/api.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export function get_api_base_url() {
|
||||
return "http://localhost:8000/api";
|
||||
}
|
||||
1
template/web/js/uikit-icons.min.js
vendored
Normal file
1
template/web/js/uikit-icons.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
template/web/js/uikit.min.js
vendored
Normal file
1
template/web/js/uikit.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
template/web/src/components/mod.rs
Normal file
1
template/web/src/components/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod object;
|
||||
23
template/web/src/components/object.rs
Normal file
23
template/web/src/components/object.rs
Normal 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
46
template/web/src/lib.rs
Normal 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
5
template/web/src/main.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
use {{crate_name}}_web::App;
|
||||
|
||||
fn main() {
|
||||
yew::start_app::<App>();
|
||||
}
|
||||
Reference in New Issue
Block a user