From a45eac79fbfeabf2c235912b70d6a79ebb68933a Mon Sep 17 00:00:00 2001 From: YuKun Liu Date: Tue, 7 Mar 2023 17:10:15 -0800 Subject: [PATCH] fix: `dioxus fmt` --- src/components/content.rs | 15 ++----------- src/components/footer.rs | 24 +++++--------------- src/main.rs | 21 +++++------------- src/pages/_404.rs | 12 ++++------ src/pages/starter.rs | 46 +++++++++++++-------------------------- 5 files changed, 31 insertions(+), 87 deletions(-) diff --git a/src/components/content.rs b/src/components/content.rs index 09febb4..c72f29b 100644 --- a/src/components/content.rs +++ b/src/components/content.rs @@ -5,12 +5,7 @@ use crate::hooks::markdown::use_markdown; #[inline_props] pub fn Href<'a>(cx: Scope, to: &'a str, children: Element<'a>) -> Element { cx.render(rsx! { - a { - class: "text-cyan-700 dark:text-cyan-100 underline", - href: "{to}", - target: "_blank", - children - } + a { class: "text-cyan-700 dark:text-cyan-100 underline", href: "{to}", target: "_blank", children } }) } @@ -25,11 +20,5 @@ pub fn Markdown<'a>(cx: Scope<'a, MarkdownProps<'a>>) -> Element { let md_parser = use_markdown(&cx); let content = md_parser(cx.props.content.clone()); let extra_class = &cx.props.class; - cx.render(rsx! { - div { - id: "markdown-body", - class: "prose {extra_class}", - dangerous_inner_html: "{content}", - } - }) + cx.render(rsx! {div { id: "markdown-body", class: "prose {extra_class}", dangerous_inner_html: "{content}" }}) } diff --git a/src/components/footer.rs b/src/components/footer.rs index 4524ca7..d02d8eb 100644 --- a/src/components/footer.rs +++ b/src/components/footer.rs @@ -11,16 +11,11 @@ pub fn Footer(cx: Scope) -> Element { log::info!("dark mode: {:?}", is_dark(&cx)); let current_mode = is_dark(&cx); cx.render(rsx! { - div { - class: "mt-6 flex space-x-4 justify-center", + div { class: "mt-6 flex space-x-4 justify-center", Link { class: "text-black dark:text-white hover:text-gray-800 dark:hover:text-gray-200", to: "/", - Icon { - height: 26, - width: 26, - icon: fa_solid_icons::FaHouse - } + Icon { height: 26, width: 26, icon: fa_solid_icons::FaHouse } } a { class: "text-black dark:text-white hover:text-gray-800 dark:hover:text-gray-200", @@ -51,24 +46,15 @@ pub fn Footer(cx: Scope) -> Element { Link { class: "text-black dark:text-white hover:text-gray-800 dark:hover:text-gray-200", to: "/about", - Icon { - height: 26, - width: 26, - icon: fa_solid_icons::FaBook - } + Icon { height: 26, width: 26, icon: fa_solid_icons::FaBook } } a { class: "text-black dark:text-white hover:text-gray-800 dark:hover:text-gray-200", href: "https://github.com/mrxiaozhuox/dioxus-starter", - Icon { - height: 26, - width: 26, - icon: fa_brands_icons::FaGithub - } + Icon { height: 26, width: 26, icon: fa_brands_icons::FaGithub } } } - div { - class: "mt-10 flex justify-center text-gray-400", + div { class: "mt-10 flex justify-center text-gray-400", span { "[ made by " a { diff --git a/src/main.rs b/src/main.rs index 9c1e477..aea4ff8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,23 +30,12 @@ fn App(cx: Scope) -> Element { cx.render(rsx! { // dioxus toast manager init - ToastFrame { - manager: use_atom_ref(&cx, TOAST_MANAGER), - } + ToastFrame { manager: use_atom_ref(&cx, TOAST_MANAGER) } // dioxus router info - Router { - Route { - to: "/", - HelloDioxus {} - } - Route { - to: "/hi/:name", - SayHi {} - } - Route { - to: "/about", - About {} - } + Router { + Route { to: "/", HelloDioxus {} } + Route { to: "/hi/:name", SayHi {} } + Route { to: "/about", About {} } // 404 page Route { to: "", pages::_404::NotFound {} } } diff --git a/src/pages/_404.rs b/src/pages/_404.rs index c0b2da1..686008a 100644 --- a/src/pages/_404.rs +++ b/src/pages/_404.rs @@ -4,14 +4,10 @@ use crate::components::footer::Footer; pub fn NotFound(cx: Scope) -> Element { cx.render(rsx! { - section { - class: "h-screen bg-cover bg-white dark:bg-gray-600", - div { - class: "flex h-full w-full items-center justify-center container mx-auto px-8", - div { - class: "max-w-2xl text-center", - h1 { - class: "text-3xl sm:text-5xl capitalize tracking-widest dark:text-white lg:text-6xl", + section { class: "h-screen bg-cover bg-white dark:bg-gray-600", + div { class: "flex h-full w-full items-center justify-center container mx-auto px-8", + div { class: "max-w-2xl text-center", + h1 { class: "text-3xl sm:text-5xl capitalize tracking-widest dark:text-white lg:text-6xl", "Page Not Found" } Footer {} diff --git a/src/pages/starter.rs b/src/pages/starter.rs index 29cf191..67cbd98 100644 --- a/src/pages/starter.rs +++ b/src/pages/starter.rs @@ -15,22 +15,16 @@ pub fn HelloDioxus(cx: Scope) -> Element { let toast = use_atom_ref(&cx, TOAST_MANAGER); cx.render(rsx! { - section { - class: "h-screen bg-cover bg-white dark:bg-gray-600", - div { - class: "flex h-full w-full items-center justify-center container mx-auto px-8", - div { - class: "max-w-2xl text-center", - h1 { - class: "text-3xl sm:text-5xl capitalize tracking-widest text-gray-600 dark:text-white lg:text-6xl", + section { class: "h-screen bg-cover bg-white dark:bg-gray-600", + div { class: "flex h-full w-full items-center justify-center container mx-auto px-8", + div { class: "max-w-2xl text-center", + h1 { class: "text-3xl sm:text-5xl capitalize tracking-widest text-gray-600 dark:text-white lg:text-6xl", "Dioxus Starter" } - p { - class: "mt-6 lg:text-lg text-gray-600 dark:text-white", + p { class: "mt-6 lg:text-lg text-gray-600 dark:text-white", "Opinionated Dioxus Starter Template" } - div { - class: "mt-8 flex flex-col space-y-3 sm:-mx-2 sm:flex-row sm:justify-center sm:space-y-0", + div { class: "mt-8 flex flex-col space-y-3 sm:-mx-2 sm:flex-row sm:justify-center sm:space-y-0", input { r#type: "text", class: "rounded-md border border-transparent bg-gray-800 dark:bg-white/20 px-4 py-2 text-white placeholder-white backdrop-blur-sm focus:border-blue-400 focus:outline-none focus:ring focus:ring-blue-300 focus:ring-opacity-40 sm:mx-2", @@ -64,15 +58,11 @@ pub fn SayHi(cx: Scope) -> Element { let name = route.segment("name").unwrap(); let name = urlencoding::decode(name).expect("UTF-8").to_string(); cx.render(rsx! { - section { - class: "h-screen bg-cover bg-white dark:bg-gray-600", - div { - class: "flex h-full w-full items-center justify-center container mx-auto px-8", - div { - class: "max-w-2xl text-center", - h1 { - class: "text-3xl sm:text-5xl capitalize tracking-widest dark:text-white lg:text-6xl", - "Hi, \"{name}\"" + section { class: "h-screen bg-cover bg-white dark:bg-gray-600", + div { class: "flex h-full w-full items-center justify-center container mx-auto px-8", + div { class: "max-w-2xl text-center", + h1 { class: "text-3xl sm:text-5xl capitalize tracking-widest dark:text-white lg:text-6xl", + "Hi, "{name}"" } Footer {} } @@ -84,17 +74,11 @@ pub fn SayHi(cx: Scope) -> Element { pub fn About(cx: Scope) -> Element { let content = include_str!("../markdown/readme.md"); cx.render(rsx! { - div { - class: "dark:bg-gray-600", + div { class: "dark:bg-gray-600", br {} - div { - class: "md:flex md:justify-center", - div { - class: "block p-8 rounded-lg shadow-2xl bg-white dark:bg-gray-700", - Markdown { - class: "dark:text-white", - content: content.to_string() - } + div { class: "md:flex md:justify-center", + div { class: "block p-8 rounded-lg shadow-2xl bg-white dark:bg-gray-700", + Markdown { class: "dark:text-white", content: content.to_string() } } } Footer {}