boilerplate

This commit is contained in:
2026-03-10 14:29:43 +01:00
commit 2d19e3b5d7
23 changed files with 6997 additions and 0 deletions

37
src/components/echo.rs Normal file
View File

@ -0,0 +1,37 @@
use dioxus::prelude::*;
const ECHO_CSS: Asset = asset!("/assets/styling/echo.css");
#[component]
pub fn Echo() -> Element {
let mut response = use_signal(|| String::new());
rsx! {
document::Link { rel: "stylesheet", href: ECHO_CSS }
div {
id: "echo",
h4 { "ServerFn Echo" }
input {
placeholder: "Type here to echo...",
oninput: move |event| async move {
let data = echo_server(event.value()).await.unwrap();
response.set(data);
},
}
if !response().is_empty() {
p {
"Server echoed: "
i { "{response}" }
}
}
}
}
}
#[post("/api/echo")]
async fn echo_server(input: String) -> Result<String> {
Ok(input)
}

21
src/components/hero.rs Normal file
View File

@ -0,0 +1,21 @@
use dioxus::prelude::*;
const HEADER_SVG: Asset = asset!("/assets/header.svg");
#[component]
pub fn Hero() -> Element {
rsx! {
div {
id: "hero",
img { src: HEADER_SVG, id: "header" }
div { id: "links",
a { href: "https://dioxuslabs.com/learn/0.7/", "📚 Learn Dioxus" }
a { href: "https://dioxuslabs.com/awesome", "🚀 Awesome Dioxus" }
a { href: "https://github.com/dioxus-community/", "📡📡 📡 📡 📡" }
a { href: "https://github.com/DioxusLabs/sdk", "⚙️ Dioxus Development Kit" }
a { href: "https://marketplace.visualstudio.com/items?itemName=DioxusLabs.dioxus", "some useless shit" }
a { href: "https://discord.gg/XgGxMSkvUM", "who tf uses discord ??" }
}
}
}
}

6
src/components/mod.rs Normal file
View File

@ -0,0 +1,6 @@
mod hero;
pub use hero::Hero;
mod echo;
pub use echo::Echo;

36
src/main.rs Normal file
View File

@ -0,0 +1,36 @@
use dioxus::prelude::*;
use views::{Blog, Home, Navbar};
mod components;
mod views;
#[derive(Debug, Clone, Routable, PartialEq)]
#[rustfmt::skip]
enum Route {
#[layout(Navbar)]
#[route("/")]
Home {},
#[route("/blog/:id")]
Blog { id: i32 },
}
const FAVICON: Asset = asset!("/assets/favicon.ico");
const MAIN_CSS: Asset = asset!("/assets/styling/main.css");
const TAILWIND_CSS: Asset = asset!("/assets/tailwind.css");
fn main() {
dioxus::launch(App);
}
#[component]
fn App() -> Element {
rsx! {
document::Link { rel: "icon", href: FAVICON }
document::Link { rel: "stylesheet", href: MAIN_CSS }
document::Link { rel: "stylesheet", href: TAILWIND_CSS }
Router::<Route> {}
}
}

30
src/views/blog.rs Normal file
View File

@ -0,0 +1,30 @@
use crate::Route;
use dioxus::prelude::*;
use crate::components::{Hero};
const BLOG_CSS: Asset = asset!("/assets/styling/blog.css");
#[component]
pub fn Blog(id: i32) -> Element {
rsx! {
document::Link { rel: "stylesheet", href: BLOG_CSS }
div {
id: "blog",
h1 { "This is blog #{id}!" }
p { "In blog #{id}, we show how the Dioxus router works and how URL parameters can be passed as props to our route components." }
Link {
to: Route::Blog { id: id - 1 },
"Previous"
}
span { " <---> " }
Link {
to: Route::Blog { id: id + 1 },
"Next"
}
}
Hero{}
}
}

11
src/views/home.rs Normal file
View File

@ -0,0 +1,11 @@
use dioxus::prelude::*;
use crate::components::{Hero, Echo};
/// The Home page component that will be rendered when the current route is `[Route::Home]`
#[component]
pub fn Home() -> Element {
rsx! {
Hero {}
Echo {}
}
}

8
src/views/mod.rs Normal file
View File

@ -0,0 +1,8 @@
mod home;
pub use home::Home;
mod blog;
pub use blog::Blog;
mod navbar;
pub use navbar::Navbar;

25
src/views/navbar.rs Normal file
View File

@ -0,0 +1,25 @@
use crate::Route;
use dioxus::prelude::*;
const NAVBAR_CSS: Asset = asset!("/assets/styling/navbar.css");
#[component]
pub fn Navbar() -> Element {
rsx! {
document::Link { rel: "stylesheet", href: NAVBAR_CSS }
div {
id: "navbar",
Link {
to: Route::Home {},
"Home"
}
Link {
to: Route::Blog { id: 1 },
"Blog"
}
}
Outlet::<Route> {}
}
}