From 9e433c5e67f59e05d6b5eb99f330c69e5ac7069c Mon Sep 17 00:00:00 2001 From: luoxiao Date: Mon, 5 Aug 2024 14:08:46 +0800 Subject: [PATCH] feat: optimized routing --- demo/src/app.rs | 113 +++++++++++------------- demo/src/components/site_header.rs | 15 ++-- demo/src/pages/components.rs | 137 +++++++++++++---------------- thaw/src/icon/mod.rs | 8 +- 4 files changed, 123 insertions(+), 150 deletions(-) diff --git a/demo/src/app.rs b/demo/src/app.rs index ba3f23d..5ea61e6 100644 --- a/demo/src/app.rs +++ b/demo/src/app.rs @@ -3,7 +3,7 @@ use leptos::{prelude::*, reactive_graph::wrappers::write::SignalSetter}; use leptos_meta::provide_meta_context; use leptos_router::{ components::{ParentRoute, Route, Router, Routes}, - StaticSegment, + path, }; // use leptos_use::{ // storage::use_local_storage, @@ -41,79 +41,72 @@ fn TheRouter(is_routing: RwSignal) -> impl IntoView { view! { - - - - - + + + + + - - - // // - // // - // // + { view! { - - - - - - - - - - - - - - + + + + + + + + + + + + + + } } { view! { - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + } } { view! { - - - - - - - - + + + + + + + + + + + + + + + + } } - - - - - - - - - // - // - // } } diff --git a/demo/src/components/site_header.rs b/demo/src/components/site_header.rs index 1831fc7..fe42d2d 100644 --- a/demo/src/components/site_header.rs +++ b/demo/src/components/site_header.rs @@ -166,8 +166,8 @@ pub fn SiteHeader() -> impl IntoView { on_select=move |value : String| match value.as_str() { "Dark" => change_theme(MouseEvent::new("click").unwrap()), "Light" => change_theme(MouseEvent::new("click").unwrap()), - "github" => { _ = window().open_with_url("http://github.com/thaw-ui/thaw"); },//FIXME: breaks page - "discord" => { _ = window().open_with_url("https://discord.gg/YPxuprzu6M"); },//FIXME: breaks page + "github" => { _ = window().open_with_url("http://github.com/thaw-ui/thaw"); }, + "discord" => { _ = window().open_with_url("https://discord.gg/YPxuprzu6M"); }, _ => navigate_signal.get()(&value, Default::default()) } @@ -183,16 +183,16 @@ pub fn SiteHeader() -> impl IntoView { "Github" "Discord" { - use crate::pages::{gen_menu_data, MenuGroupOption, MenuItemOption}; - gen_menu_data().into_iter().map(|data| { - let MenuGroupOption { label, children } = data; + use crate::pages::{gen_nav_data, NavGroupOption, NavItemOption}; + gen_nav_data().into_iter().map(|data| { + let NavGroupOption { label, children } = data; view! { {label} { children.into_iter().map(|item| { - let MenuItemOption { label, value } = item; + let NavItemOption { label, value } = item; view! { {label} } @@ -246,8 +246,7 @@ struct AutoCompleteOption { } fn gen_search_all_options() -> Vec { - use crate::pages::gen_menu_data; - gen_menu_data() + crate::pages::gen_nav_data() .into_iter() .flat_map(|group| { group.children.into_iter().map(|item| AutoCompleteOption { diff --git a/demo/src/pages/components.rs b/demo/src/pages/components.rs index 6e6b795..285ad5e 100644 --- a/demo/src/pages/components.rs +++ b/demo/src/pages/components.rs @@ -58,15 +58,15 @@ pub fn ComponentsPage() -> impl IntoView {
{ - gen_menu_data().into_iter().map(|data| { - let MenuGroupOption { label, children } = data; + gen_nav_data().into_iter().map(|data| { + let NavGroupOption { label, children } = data; view! { {label} { children.into_iter().map(|item| { - let MenuItemOption { label, value } = item; + let NavItemOption { label, value } = item; view! { {label} } @@ -85,245 +85,228 @@ pub fn ComponentsPage() -> impl IntoView { } } -pub(crate) struct MenuGroupOption { +pub(crate) struct NavGroupOption { pub label: String, - pub children: Vec, + pub children: Vec, } -pub(crate) struct MenuItemOption { +pub(crate) struct NavItemOption { pub label: String, pub value: String, } -pub(crate) fn gen_menu_data() -> Vec { +pub(crate) fn gen_nav_data() -> Vec { vec![ - MenuGroupOption { + NavGroupOption { label: "Getting Started".into(), children: vec![ - MenuItemOption { + NavItemOption { value: "/guide/installation".into(), label: "Installation".into(), }, - MenuItemOption { + NavItemOption { value: "/guide/server-sider-rendering".into(), label: "Server Sider Rendering".into(), }, ], }, - // MenuGroupOption { + // NavGroupOption { // label: "Development".into(), // children: vec![ - // MenuItemOption { + // NavItemOption { // value: "/guide/development/components".into(), // label: "Components".into(), // }, // ], // }, - MenuGroupOption { + NavGroupOption { label: "Components".into(), children: vec![ - MenuItemOption { + NavItemOption { value: "/components/accordion".into(), label: "Accordion".into(), }, - MenuItemOption { + NavItemOption { value: "/components/anchor".into(), label: "Anchor".into(), }, - MenuItemOption { + NavItemOption { value: "/components/auto-complete".into(), label: "Auto Complete".into(), }, - MenuItemOption { + NavItemOption { value: "/components/avatar".into(), label: "Avatar".into(), }, - MenuItemOption { + NavItemOption { value: "/components/back-top".into(), label: "Back Top".into(), }, - MenuItemOption { + NavItemOption { value: "/components/badge".into(), label: "Badge".into(), }, - MenuItemOption { + NavItemOption { value: "/components/breadcrumb".into(), label: "Breadcrumb".into(), }, - MenuItemOption { + NavItemOption { value: "/components/button".into(), label: "Button".into(), }, - MenuItemOption { + NavItemOption { value: "/components/calendar".into(), label: "Calendar".into(), }, - MenuItemOption { + NavItemOption { value: "/components/card".into(), label: "Card".into(), }, - MenuItemOption { + NavItemOption { value: "/components/checkbox".into(), label: "Checkbox".into(), }, - MenuItemOption { + NavItemOption { value: "/components/color-picker".into(), label: "Color Picker".into(), }, - MenuItemOption { + NavItemOption { value: "/components/combobox".into(), label: "Combobox".into(), }, - MenuItemOption { + NavItemOption { value: "/components/config-provider".into(), label: "Config Provider".into(), }, - MenuItemOption { + NavItemOption { value: "/components/date-picker".into(), label: "Date Picker".into(), }, - MenuItemOption { + NavItemOption { value: "/components/dialog".into(), label: "Dialog".into(), }, - MenuItemOption { + NavItemOption { value: "/components/divider".into(), label: "Divider".into(), }, - MenuItemOption { + NavItemOption { value: "/components/drawer".into(), label: "Drawer".into(), }, - MenuItemOption { + NavItemOption { value: "/components/grid".into(), label: "Grid".into(), }, - MenuItemOption { + NavItemOption { value: "/components/icon".into(), label: "Icon".into(), }, - MenuItemOption { + NavItemOption { value: "/components/image".into(), label: "Image".into(), }, - MenuItemOption { + NavItemOption { value: "/components/input".into(), label: "Input".into(), }, - MenuItemOption { + NavItemOption { value: "/components/layout".into(), label: "Layout".into(), }, - MenuItemOption { + NavItemOption { value: "/components/loading-bar".into(), label: "Loading Bar".into(), }, - MenuItemOption { + NavItemOption { value: "/components/menu".into(), label: "Menu".into(), }, - MenuItemOption { + NavItemOption { value: "/components/message-bar".into(), label: "Message Bar".into(), }, - MenuItemOption { + NavItemOption { value: "/components/nav".into(), label: "Nav".into(), }, - MenuItemOption { - value: "pagination".into(), + NavItemOption { + value: "/components/pagination".into(), label: "Pagination".into(), }, - MenuItemOption { + NavItemOption { value: "/components/popover".into(), label: "Popover".into(), }, - MenuItemOption { + NavItemOption { value: "/components/progress-bar".into(), label: "ProgressBar".into(), }, - MenuItemOption { + NavItemOption { value: "/components/radio".into(), label: "Radio".into(), }, - MenuItemOption { + NavItemOption { value: "/components/scrollbar".into(), label: "Scrollbar".into(), }, - MenuItemOption { + NavItemOption { value: "/components/skeleton".into(), label: "Skeleton".into(), }, - MenuItemOption { + NavItemOption { value: "/components/slider".into(), label: "Slider".into(), }, - MenuItemOption { + NavItemOption { value: "/components/space".into(), label: "Space".into(), }, - MenuItemOption { + NavItemOption { value: "/components/spin-button".into(), label: "Spin Button".into(), }, - MenuItemOption { + NavItemOption { value: "/components/spinner".into(), label: "Spinner".into(), }, - MenuItemOption { + NavItemOption { value: "/components/switch".into(), label: "Switch".into(), }, - MenuItemOption { + NavItemOption { value: "/components/tab-list".into(), label: "Tab List".into(), }, - MenuItemOption { + NavItemOption { value: "/components/table".into(), label: "Table".into(), }, - MenuItemOption { + NavItemOption { value: "/components/tag".into(), label: "Tag".into(), }, - MenuItemOption { + NavItemOption { value: "/components/text".into(), label: "Text".into(), }, - MenuItemOption { + NavItemOption { value: "/components/textarea".into(), label: "Textarea".into(), }, - MenuItemOption { + NavItemOption { value: "/components/time-picker".into(), label: "Time Picker".into(), }, - MenuItemOption { + NavItemOption { value: "/components/toast".into(), label: "Toast".into(), }, - MenuItemOption { + NavItemOption { value: "/components/upload".into(), label: "Upload".into(), }, ], }, - // MenuGroupOption { - // label: "Mobile Components".into(), - // children: vec![ - // MenuItemOption { - // value: "/components/nav-bar".into(), - // label: "Nav Bar".into(), - // }, - // MenuItemOption { - // value: "/components/tabbar".into(), - // label: "Tabbar".into(), - // }, - // MenuItemOption { - // value: "/components/toast".into(), - // label: "Toast".into(), - // }, - // ], - // }, ] } diff --git a/thaw/src/icon/mod.rs b/thaw/src/icon/mod.rs index af691af..ac4ffa1 100644 --- a/thaw/src/icon/mod.rs +++ b/thaw/src/icon/mod.rs @@ -80,7 +80,7 @@ pub fn Icon( icon_data.set(Some(icon.data.to_string())); }); - let svg = view! { + view! { - }; - - svg.inner_html(move || take(icon_data)) + } } fn take_signal(signal: RwSignal>>) -> Option {