diff --git a/smart-house-web/Cargo.toml b/smart-house-web/Cargo.toml index 7d13ab9..c9f562d 100644 --- a/smart-house-web/Cargo.toml +++ b/smart-house-web/Cargo.toml @@ -2,6 +2,7 @@ members = [ "backend", "frontend", + "frontend-old", ] resolver = "3" diff --git a/smart-house-web/frontend-old/Cargo.toml b/smart-house-web/frontend-old/Cargo.toml new file mode 100644 index 0000000..ef3b1d0 --- /dev/null +++ b/smart-house-web/frontend-old/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "frontend-old" +version = "0.1.0" +edition = "2021" + +[dependencies] +dioxus = { version = "0.7", features = ["fullstack", "router"] } +reqwest = { version = "0.13", features = ["json"] } +serde = { version = "1.0", features = ["derive"] } + +[features] +default = ["web"] +web = ["dioxus/web"] +desktop = ["dioxus/desktop"] +mobile = ["dioxus/mobile"] +server = ["dioxus/server"] diff --git a/smart-house-web/frontend/Dioxus.toml b/smart-house-web/frontend-old/Dioxus.toml similarity index 100% rename from smart-house-web/frontend/Dioxus.toml rename to smart-house-web/frontend-old/Dioxus.toml diff --git a/smart-house-web/frontend/assets/favicon.ico b/smart-house-web/frontend-old/assets/favicon.ico similarity index 100% rename from smart-house-web/frontend/assets/favicon.ico rename to smart-house-web/frontend-old/assets/favicon.ico diff --git a/smart-house-web/frontend/assets/header.svg b/smart-house-web/frontend-old/assets/header.svg similarity index 100% rename from smart-house-web/frontend/assets/header.svg rename to smart-house-web/frontend-old/assets/header.svg diff --git a/smart-house-web/frontend/assets/main.css b/smart-house-web/frontend-old/assets/main.css similarity index 100% rename from smart-house-web/frontend/assets/main.css rename to smart-house-web/frontend-old/assets/main.css diff --git a/smart-house-web/frontend/clippy.toml b/smart-house-web/frontend-old/clippy.toml similarity index 100% rename from smart-house-web/frontend/clippy.toml rename to smart-house-web/frontend-old/clippy.toml diff --git a/smart-house-web/frontend/src/backend.rs b/smart-house-web/frontend-old/src/backend.rs similarity index 100% rename from smart-house-web/frontend/src/backend.rs rename to smart-house-web/frontend-old/src/backend.rs diff --git a/smart-house-web/frontend/src/components/favorites.rs b/smart-house-web/frontend-old/src/components/favorites.rs similarity index 100% rename from smart-house-web/frontend/src/components/favorites.rs rename to smart-house-web/frontend-old/src/components/favorites.rs diff --git a/smart-house-web/frontend/src/components/mod.rs b/smart-house-web/frontend-old/src/components/mod.rs similarity index 100% rename from smart-house-web/frontend/src/components/mod.rs rename to smart-house-web/frontend-old/src/components/mod.rs diff --git a/smart-house-web/frontend/src/components/nav.rs b/smart-house-web/frontend-old/src/components/nav.rs similarity index 100% rename from smart-house-web/frontend/src/components/nav.rs rename to smart-house-web/frontend-old/src/components/nav.rs diff --git a/smart-house-web/frontend/src/components/view.rs b/smart-house-web/frontend-old/src/components/view.rs similarity index 100% rename from smart-house-web/frontend/src/components/view.rs rename to smart-house-web/frontend-old/src/components/view.rs diff --git a/smart-house-web/frontend-old/src/main.rs b/smart-house-web/frontend-old/src/main.rs new file mode 100644 index 0000000..7f853bf --- /dev/null +++ b/smart-house-web/frontend-old/src/main.rs @@ -0,0 +1,74 @@ +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; + +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:: { } + } +} + +#[component] +fn Title() -> Element { + let title = use_context::(); + 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::() + .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, +} diff --git a/smart-house-web/frontend/Cargo.toml b/smart-house-web/frontend/Cargo.toml index fc2f171..1a91109 100644 --- a/smart-house-web/frontend/Cargo.toml +++ b/smart-house-web/frontend/Cargo.toml @@ -1,16 +1,7 @@ [package] name = "frontend" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] -dioxus = { version = "0.7", features = ["fullstack", "router"] } -reqwest = { version = "0.13", features = ["json"] } -serde = { version = "1.0", features = ["derive"] } - -[features] -default = ["web"] -web = ["dioxus/web"] -desktop = ["dioxus/desktop"] -mobile = ["dioxus/mobile"] -server = ["dioxus/server"] +leptos = { version = "0.8.19", features = ["csr"] } diff --git a/smart-house-web/frontend/index.html b/smart-house-web/frontend/index.html new file mode 100644 index 0000000..7f2ad66 --- /dev/null +++ b/smart-house-web/frontend/index.html @@ -0,0 +1,5 @@ + + + + + diff --git a/smart-house-web/frontend/src/main.rs b/smart-house-web/frontend/src/main.rs index 7f853bf..3bfc6b4 100644 --- a/smart-house-web/frontend/src/main.rs +++ b/smart-house-web/frontend/src/main.rs @@ -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:: { } - } -} - -#[component] -fn Title() -> Element { - let title = use_context::(); - 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::() - .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! {

"Hello, world!"

}) }