smart-house-web: переход на leptos

This commit is contained in:
16 changed files with 100 additions and 82 deletions

View File

@@ -1,74 +1,5 @@
use dioxus::prelude::*;
use crate::components::{Favorites, NavBar};
const FAVICON: Asset = asset!("/assets/favicon.ico");
const MAIN_CSS: Asset = asset!("/assets/main.css");
mod backend;
mod components;
use leptos::prelude::*;
fn main() {
dioxus::launch(App);
}
#[derive(Clone)]
struct TitleState(String);
#[component]
fn App() -> Element {
use_context_provider(|| TitleState("HotDog".to_string()));
rsx! {
document::Link { rel: "icon", href: FAVICON }
document::Stylesheet { href: MAIN_CSS }
Router::<Route> { }
}
}
#[component]
fn Title() -> Element {
let title = use_context::<TitleState>();
rsx! {
div { id: "title",
h1 { "{title.0}! 🌭" }
}
}
}
#[derive(serde::Deserialize)]
struct DogApi {
message: String,
}
#[component]
fn DogView() -> Element {
let mut img_src = use_resource(|| async move {
reqwest::get("https://dog.ceo/api/breeds/image/random")
.await
.unwrap()
.json::<DogApi>()
.await
.unwrap()
.message
});
rsx! {
div { id: "dogview",
img { src: img_src.cloned().unwrap_or_default() }
}
div { id: "buttons",
button { onclick: move |_| img_src.restart(), id: "skip", "skip" }
button { onclick: move |_| img_src.restart(), id: "save", "save!" }
}
}
}
#[derive(Routable, Clone, PartialEq)]
enum Route {
#[layout(NavBar)]
#[route("/")]
DogView,
#[route("/favorites")]
Favorites,
leptos::mount::mount_to_body(|| view! { <p>"Hello, world!"</p> })
}